开发者

how to find the file is created or updated current date/day

开发者 https://www.devze.com 2023-01-22 13:36 出处:网络
how to find the file is created o开发者_JAVA百科r updated current date/dayYou could use the -M function to see if the file has been modified in the last day:

how to find the file is created o开发者_JAVA百科r updated current date/day


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.


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";


Show on File::Stat. You can use DateTime to init the timestamp with local time zone.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号