perl.beginners
[Top] [All Lists]

Re: how to iterate through a list of files in a directory and comparethe

Subject: Re: how to iterate through a list of files in a directory and comparethem to an index.
From: Gunnar Hjalmarsson
Date: Fri, 07 Mar 2008 19:13:45 +0100
Newsgroups: perl.beginners


John W. Krahn wrote:
Angus Glanville wrote:


<snip>

My final goal is to normalize the names so that they are the same case on the file system as indicated in the index file.

<snip>

You probably need to use the -e (exists) file test operator:

while ( my $line = <INDEX> ) {
    chomp $line;
    my ( $raw_name, $std_name ) = split /\|/, $line;
    if ( -e "$pdf_dir/$std_name" ) {
        print "I found this: $std_name\n";
    }
}

Since case may differ, that code might fail to find some of the files (at least on non-Windows platforms).

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

<Prev in Thread] Current Thread [Next in Thread>