# PERL: Determine if a folder/file exists?



## michaelsanford (Mar 7, 2003)

I seem to remember seeing somewhere in a sh or pl script, syntax similar to

IF EXIST $folder {
	&install;
} else {
	&create_folder;
	&install;
}

Or something to that effect, but not that exactly.

I need to know how to determine if a file or folder exists on the system (I can pass it the absolute path, so I can check for mounted volumes with known names especially).

Thanks!


----------



## MacMarshall (Mar 12, 2003)

Give this a try --

if (-e $folder) { 
   &install; 
} else { 
   &create_folder; 
   &install; 
}

But it's better written like this (TMTOWTDI):

unless (-e $folder) {&create_folder}
&install;


----------



## michaelsanford (Mar 12, 2003)

Cool thanks, I found the -e switch somewhere but I wasn't sure it worked on folders, this is perfect.


----------



## kukident (Mar 17, 2003)

*-d $path* tells you if it's a directory (and not a file).
*-w $path* tells you if you can write to it.

check this


----------



## michaelsanford (Mar 17, 2003)

Cool that is useful too, thanks!


----------

