how to find the file is created or updated current date/day
+3
A:
You could use the -M
function to see if the file has been modified in the last day:
if(-M FH < 1) {
# file was modified less than one day ago
}
You can also test for time since the inode was changed with -C
, which is often (but not always) when the file was created (see here for filesystem compatibility issues).
See here for some examples of the various filetests.
Jeremy Smyth
2010-10-28 08:44:50
+1
A:
Show on File::Stat. You can use DateTime to init the timestamp with local time zone.
xGhost
2010-10-28 08:45:21
+2
A:
Assuming that you want day and date of the file when it was last modified, you can try like this
use strict;
use warning;
use File::stat;
use Time::localtime;
my $st = stat($file) or die "No $file: $!";
my $datetime_string = ctime($st->mtime);
print "file $file was updated at $datetime_string\n";
Nikhil Jain
2010-10-28 09:19:29