Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: comparing 2 file time date stamps

by Corion (Patriarch)
on Nov 06, 2014 at 11:02 UTC ( #1106349=note: print w/replies, xml ) Need Help??


in reply to comparing 2 file time date stamps

From the discussion, it seems that for some weird reason, you get different results in the mtime field of stat than you expect.

How are you building your expectation of what is correct?

The following program should output the correct mtime for each file, which should be identical with what the OS thinks, as verified via dir:

use strict; for my $file (@ARGV) { print "Checking '$file'\n"; if( -f $file ) { system("dir $file"); my $mtime= (stat($file))[9]; print "Mtime: $mtime\n"; print "As string: " . localtime($mtime); } else { print "File '$file' does not exist, skipping\n"; }; }; __END__ Checking 'tmp.pl' Volume in Laufwerk Q: hat keine Bezeichnung. Volumeseriennummer: 5A02-C2B6 Verzeichnis von Q:\ 06.11.2014 12:01 336 tmp.pl 1 Datei(en), 336 Bytes 0 Verzeichnis(se), 956.154.372.096 Bytes frei Mtime: 1415271660 As string: Thu Nov 6 12:01:00 2014

Ideally, you should always find that the output of the timestamps as reported by dir are identical to the output of the timestamp as found via $mtime and output via localtime.

Replies are listed 'Best First'.
Re^2: comparing 2 file time date stamps
by craigt (Acolyte) on Nov 06, 2014 at 14:18 UTC
    Corion, Below is the code I ran.
    #!C:/PERL/bin/perl.exe -w use strict; my $file = 'c:/Steep/USA Data/State/KY/KY2.gif'; print "Checking '$file'\n"; if( -e $file ) { system "dir $file"; my $mtime= (stat($file))[9]; print "Mtime: $mtime\n"; print "As string: " . localtime($mtime); } else { print "File '$file' does not exist, skipping\n"; } $file = 'c:/usr/www/steepusa/stage/KY/KY2.gif'; print "\n\r\n\rChecking '$file'\n"; if( -e $file ) { system "dir $file"; my $mtime= (stat($file))[9]; print "Mtime: $mtime\n"; print "As string: " . localtime($mtime); } else { print "File '$file' does not exist, skipping\n"; }
    The output follows.
    Checking 'c:/Steep/USA Data/State/KY/KY2.gif'
    Parameter format not correct - "Steep"
    Mtime: 1415235120
    As string: Wed Nov  5 19:52:00 2014
    
    Checking 'c:/usr/www/steepusa/stage/KY/KY2.gif'
    Invalid switch - "usr"
    Mtime: 1415235120
    As string: Wed Nov  5 19:52:00 2014
    

    The system command doesn't seem to like the file name as I've formed it.

      Ah - if you specify the path names with backslashes instead of forward slashes, the Windows built-in tools will understand them from the command line:

      my $file = "c:\\Steep\\USA Data\\State\\KY\\KY2.gif";
        It still barks at the space in the USA Data. I've tried several suggestions, as this is pretty common apparently, to no avail.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1106349]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2022-08-08 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?