bsamuels
12-14-2003, 08:20 PM
Below is a code snippet that I used as a test (it's part of a larger program) to stat the contents of a directory. The problem is that it only works sometimes, on some files it successfully retrieves the entire stat list but on others it doesn't. This is especially true when going to another directory other than the working directory. Though this file uses the File::stat module, I get the same results in versions without. I'm confused, it seems easy enough. Can someone help.?
#!/usr/bin/perl
use File::stat;
$file = shift (@ARGV);
if( -d $file){
opendir MYDIR, $file or die"Cannot open $file: $!";
print "$file:\n";
while ($dirfiles = readdir MYDIR){
$filestats = stat($dirfiles);
print scalar localtime $filestats->mtime," $dirfiles\n";
next if $dirfiles =~ /^\./;
}
}
#!/usr/bin/perl
use File::stat;
$file = shift (@ARGV);
if( -d $file){
opendir MYDIR, $file or die"Cannot open $file: $!";
print "$file:\n";
while ($dirfiles = readdir MYDIR){
$filestats = stat($dirfiles);
print scalar localtime $filestats->mtime," $dirfiles\n";
next if $dirfiles =~ /^\./;
}
}