NarendraTTT has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,
I am reading all the files in a directory and then accessing the modify time for each of the files like so :
opendir(BIN, $dir) or die "Can't open $dir: $!"; while( defined ($file = readdir BIN) ) { next if !($file =~ /^TT\.*/); $mtime= (stat($file))[9]; ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDa +y, $DayOfYear, $IsDST) = localtime($mtime); $Month=$Month+1; print $Year."\n"; $Year=$Year-100; ......
But, I keep getting modify date of 1/1/1970 for ALL the files in the directory even though they were modified yesterday, today etc.
Can anyone point out my mistake ?

Narendra Tumkur

Replies are listed 'Best First'.
Re: Getting file properties returns 1970 modify time
by Fletch (Bishop) on Jan 06, 2005 at 04:27 UTC

    readdir doesn't put the directory name on what it returns, so when you call stat you're not getting any results (and hence $mtime is undef and localtime will return the epoch). You need to do stat( "$dir/$file" ) instead, or change your working directory to $dir.

      Thanks for that !
      Much appreciated :)

      Narendra Tumkur