1. Directory Exists??

I'm trying to create a function that checks the existence of a directory, but I
haven't found my luck yet..

Can anyone help?

Kenneth aka ZNorQ

new topic     » topic index » view message » categorize

2. Re: Directory Exists??

ZNorQ wrote:
> 
> I'm trying to create a function that checks the existence of a directory,
> but I haven't found my luck yet..
> 
> Can anyone help?
> 
> Kenneth aka ZNorQ

The Euphoria dir()

It returns -1 if no file or directory with this name is found.
If it is found, then you would need to check the attributes to find out whether
it is a file or a directory.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Directory Exists??

Jerry Story wrote:
> 
> ZNorQ wrote:
> > 
> > I'm trying to create a function that checks the existence of a directory,
> > but I haven't found my luck yet..
> > 
> > Can anyone help?
> > 
> > Kenneth aka ZNorQ
> 
> The Euphoria dir()
> 
> It returns -1 if no file or directory with this name is found.
> If it is found, then you would need to check the attributes to find out
> whether
> it is a file or a directory.


Yeah, I saw that, but I was hoping there was an other command, since this would
actually use time to create an index of the content (don't it?). I would like a
function that uses as little time as possible to just confirm if a FOLDER exists.

Thanks anyway. :)

ZNorQ

new topic     » goto parent     » topic index » view message » categorize

4. Re: Directory Exists??

The following is probably the simpleist and fastest method with native Euphoria
functions:

function directoryExists(sequence path)
sequence currentdir
integer status,void
	currentdir=current_dir()
	status=chdir(path)
	if status then
		void=chdir(currentdir)
	end if
	return status
end function


Tested with Windows but should also work on Linux.

A faster method is possible using the windows api function FindFirstFile() but
it is more complex.

Larry Miller

new topic     » goto parent     » topic index » view message » categorize

5. Re: Directory Exists??

Larry Miller wrote:
> 
> The following is probably the simpleist and fastest method with native
> Euphoria
> functions: 
> 
> }}}
<eucode>
> function directoryExists(sequence path)
> sequence currentdir
> integer status,void
> 	currentdir=current_dir()
> 	status=chdir(path)
> 	if status then
> 		void=chdir(currentdir)
> 	end if
> 	return status
> end function
> </eucode>
{{{

> 
> Tested with Windows but should also work on Linux.
> 
> A faster method is possible using the windows api function FindFirstFile() but
> it is more complex.
> 
> Larry Miller

Tested and works for me. I don't know how fast.
global function exist(sequence fileOrFolder)
  object x
    x=dir(fileOrFolder)
          if atom(x) then
             return 0
          else
             return 1
          end if
end function

Don Cole

new topic     » goto parent     » topic index » view message » categorize

6. Re: Directory Exists??

Larry Miller wrote:
> 
> The following is probably the simpleist and fastest method with native
> Euphoria
> functions: 
> 
> }}}
<eucode>
> function directoryExists(sequence path)
> sequence currentdir
> integer status,void
> 	currentdir=current_dir()
> 	status=chdir(path)
> 	if status then
> 		void=chdir(currentdir)
> 	end if
> 	return status
> end function
> </eucode>
{{{

> 
> Tested with Windows but should also work on Linux.
> 
> A faster method is possible using the windows api function FindFirstFile() but
> it is more complex.
> 
> Larry Miller

Sounds good, don't mind if I implemend it - do you? :) Thanks.

Kenneth aka ZNorQ

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu