Wednesday, June 6, 2012

How to Read File names from a DIR in PERL

#Reading files from the Directory
my $dir = 'C:\Users\philip\Desktop\sample_files';
 opendir(DIR, $dir) or die $!;
 while (my $file = readdir(DIR)) {
        # Use a regular expression to ignore files beginning with a period
        next if ($file =~ m/^\./);
 print "$file\n";
    }
    closedir(DIR);

No comments:

Post a Comment