I'm using the File::Find module to search for files in a particular sub directory on my server.
I have it working but if the directory does not exist, my script seems to stall as if it's
locked in an endless search. If it finds the sub directory but it is empty it seems to move
up a directory level and returns file names from that level.
Is this normal behavior?
Is there some code that I can add to stop the search and return an error if the directory
does not exist or is empty?
Following is a snippet of code.
Thank you.
I have it working but if the directory does not exist, my script seems to stall as if it's
locked in an endless search. If it finds the sub directory but it is empty it seems to move
up a directory level and returns file names from that level.
Is this normal behavior?
Is there some code that I can add to stop the search and return an error if the directory
does not exist or is empty?
Following is a snippet of code.
Thank you.
Code:
sub get_files {
my $file;
@files=();
find (\&wanted, "/path/directory/subdirectory/");
foreach $file (@files) {
#do something
}
}
sub wanted {
#grab the actual file names using $_
my ($filename) = $_;
-f and push @files, $filename; #push only file names into an array
}