gzayzay has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to search a directory for two files I have created. If those files are found I will like to perform a particular task. However, If the files are not found, I will like to call a function that generates those files am searching for.
My problem is, I am having difficulties searching the directory to see if the file exist. I have a "for" loop as follows:
if (opendir (KDBASE, $path)) { @keywords = sort grep{$_ ne '.' and $_ ne '..'} readdir (KDBASE); for ($kdbase = 0; $kdbase <= $#keywords; $kdbase++) { if ( @keywords[$kdbase] !~ /database\.txt|keywords_databas +e\.txt/) { next; } elsif (@keywords[$kdbase] =~ /keywords_database\.txt/) { $keyword_database_present = 1; print "Keyword database found : @keywords[$kdbase]\n"; } elsif(@keywords[$kdbase] =~ /database\.txt/) { $testfilelist_database_present = 1; print "Test file list database found : @keywords[$kdba +se]\n"; } else { print "No database found yet : @keywords[$kdbase]\n"; #Generate all the necessary files. GenerateTestFileList(); } } }
I wiil like to search the entire folder first to see if my files are present. If not, then I will like the GenerateTestFileList() function to be called. What is currently happening with the above code, when every it searches the first file in the directory and it is not the file I am looking for, it calls the GenerateTestFileList() function. However, I want to search the entire directory and ensure that the files does not exit before calling the GenerateFileList() function. The Great monks kindly help me with this task?
Thanks,
Edman
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Search a directory for files
by davidrw (Prior) on Mar 09, 2006 at 20:27 UTC | |
|
Re: Search a directory for files
by philcrow (Priest) on Mar 09, 2006 at 20:25 UTC | |
| |
|
Re: Search a directory for files
by wfsp (Abbot) on Mar 09, 2006 at 20:34 UTC | |
by gzayzay (Sexton) on Mar 09, 2006 at 20:40 UTC | |
|
Re: Search a directory for files
by swkronenfeld (Hermit) on Mar 09, 2006 at 20:30 UTC | |
by gzayzay (Sexton) on Mar 09, 2006 at 20:44 UTC |