B
ben.rogers
I wrote a subroutine that finds all of the files of a certain type.
For example, if I want to find all .fm and .book files, I push these
file types to @file_types and send that to File::Find or to grep to get
my list of files (depending on whether the search should be recursive.
I print that list as shown below. Note that I get:
Open
Convert mif
Close
I haven't been able to get rid of this. Am I getting the current dir
(.) or something?
thanks for any advice,
b
################################# FIND FILES
# Print instructions for finding files to the script created by
createScriptFile.
# Get the input directory ($inputdir) and recursion setting ($recursion
= 1 or 0).
# Get the file types (@file_types) and make a string used by grep or
File::Find.
sub fileFinder {
my $file_match_string = join ("|", @file_types);
if ($recursive =~ 1) {
chdir "$inputdir";
find (\\&wanted, "$inputdir");
sub wanted(){
if (\$File::Find::name =~ /($file_match_string)\$/i && -f){
print STDOUT "FOUND: \$File::Find::name\\n";
push \@files, \$File::Find::name;
}
}
print STDOUT "Finished finding files.";
} else { # Just GREP and don't use recursion.
print "my \@files = '';\n";
print "opendir(DIR, \"$inputdir\");\n";
print "\@files = grep /$file_match_string/,";
print "readdir(DIR);\nclosedir(DIR);\n";
}
}
--------------- printed list of files -------------------------
Open
Convert mif
Close
Open C:\Adobe\mifaliscious\b4\deploying_projects.fm
Convert mif C:\Adobe\mifaliscious\b4\deploying_projects.fm
Close C:\Adobe\mifaliscious\b4\deploying_projects.fm
Open C:\Adobe\mifaliscious\b4\front.fm
Convert mif C:\Adobe\mifaliscious\b4\front.fm
Close C:\Adobe\mifaliscious\b4\front.fm
Open C:\Adobe\mifaliscious\b4\server.book
Convert mif C:\Adobe\mifaliscious\b4\server.book
Close C:\Adobe\mifaliscious\b4\server.book
Open C:\Adobe\mifaliscious\b4\serverIX.fm
Convert mif C:\Adobe\mifaliscious\b4\serverIX.fm
Close C:\Adobe\mifaliscious\b4\serverIX.fm
For example, if I want to find all .fm and .book files, I push these
file types to @file_types and send that to File::Find or to grep to get
my list of files (depending on whether the search should be recursive.
I print that list as shown below. Note that I get:
Open
Convert mif
Close
I haven't been able to get rid of this. Am I getting the current dir
(.) or something?
thanks for any advice,
b
################################# FIND FILES
# Print instructions for finding files to the script created by
createScriptFile.
# Get the input directory ($inputdir) and recursion setting ($recursion
= 1 or 0).
# Get the file types (@file_types) and make a string used by grep or
File::Find.
sub fileFinder {
my $file_match_string = join ("|", @file_types);
if ($recursive =~ 1) {
chdir "$inputdir";
find (\\&wanted, "$inputdir");
sub wanted(){
if (\$File::Find::name =~ /($file_match_string)\$/i && -f){
print STDOUT "FOUND: \$File::Find::name\\n";
push \@files, \$File::Find::name;
}
}
print STDOUT "Finished finding files.";
} else { # Just GREP and don't use recursion.
print "my \@files = '';\n";
print "opendir(DIR, \"$inputdir\");\n";
print "\@files = grep /$file_match_string/,";
print "readdir(DIR);\nclosedir(DIR);\n";
}
}
--------------- printed list of files -------------------------
Open
Convert mif
Close
Open C:\Adobe\mifaliscious\b4\deploying_projects.fm
Convert mif C:\Adobe\mifaliscious\b4\deploying_projects.fm
Close C:\Adobe\mifaliscious\b4\deploying_projects.fm
Open C:\Adobe\mifaliscious\b4\front.fm
Convert mif C:\Adobe\mifaliscious\b4\front.fm
Close C:\Adobe\mifaliscious\b4\front.fm
Open C:\Adobe\mifaliscious\b4\server.book
Convert mif C:\Adobe\mifaliscious\b4\server.book
Close C:\Adobe\mifaliscious\b4\server.book
Open C:\Adobe\mifaliscious\b4\serverIX.fm
Convert mif C:\Adobe\mifaliscious\b4\serverIX.fm
Close C:\Adobe\mifaliscious\b4\serverIX.fm