At 02:44 PM 4/18/2001, you wrote:
>I have their full name and path. The only thing I know is they end with
>"09.html". Is perl the right tool to use to find all my 09 files and place
>their fully qualified names in a file?
>
>If I can get all my 09 filenames in a file, reading them in and parsing out
>the data I need is easy.
>
>Thanks in advance for any help.
>
>Gregg R. Allen
Directory searching is easy with File::Find. Look up the docs on it if you
need more info. (
http://search.cpan.org/doc/GSAR/perl-5.6.0/lib/File/Find.pm )
use strict;
use File::Find;
open OUT, "> c:/goodfiles.txt" or die "Can't open: $!\n";
find sub {
return if -d;
print OUT "$File::Find::name\n" if /09\.html$/i;
}, 'c:/data2000';
close OUT;
Notice 2 things. The use of '/' as opposed to '\' for the path
separator. If you decide or need to use '\' you have to double all of them
('\\') as backslash is Perl's escape character, so in order to get a '\'
and not escape the next character, you have to write two of them. The
other is the /i modifier on the regex. You need to say that on some Win32
OS's, Win2000 being the one that immediately pops into my mind. I think
NT, as well. While none of them care about how you specify the path, they
will return mixed case names to File::Find, and once Perl gets a hold of
it, the filename is just a string. Since you don't know if the name will
be 'something09.html' or 'something09.HTML' you have to be sure you catch
both of them. You may also want to check out File::Basename, for parsing
the filenames up, and File::Spec, for dealing with the ways that different
filesystems handle the issues of file naming and pathing.
Thank you for your time,
Sean.