in reply to Re: Get file timestamp for a file in a directory
in thread Get file timestamp for a file in a directory
Now that your post is readable, I'd like to correct myself. POSIX::strftime will suit your formating needs, and you need to add the path to the file you're stating for it to work properly. Here's working code:
#!/usr/bin/perl use strict; use warnings; use POSIX (); my $dir = "/usr/path"; opendir(DIR, $dir); my @dir = grep { !/^\.+$/ } readdir(DIR); closedir(DIR); foreach (@dir) { my $file = "$dir/$_"; my $mtime = (stat($file))[9]; print "Last change:\t" . POSIX::strftime("%Y%m%d", localtime($mtime)) . "\n"; }
|
|---|