/ Published in: Perl
Lists last modified (or accessed) files. Based on a hint by Master Jedai at http://www.developpez.net/forums/showpost.php?p=2302596&postcount=4
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/perl -w use strict; # use File::stat; # for detailed print out use Getopt::Std; # ### get options and the argument from the command line my %opts; getopts("amc", \%opts); my $operator='-M'; # date modified to present if ($opts{'a'}) {$op='-A'}; # date accessed to present if ($opts{'c'}) {$op='-C'}; # inode change time to present # # ### store file names sorted by modification or access date # # ### with -M operator in clear # # my @files = sort { -M "$path/$a" <=> -M "$path/$b" } # grep { -f "$path/$_" } # readdir $dir; ### same with -A and -C # # ### Simple print out # foreach my $file (@files) {print "$file\n";}; # ### Detailed print out # foreach my $file (@files) {my $sb = stat("$path/$file"); printf "%s : last modified on %s, last accessed on %s\n", $file, scalar localtime $sb->mtime, scalar localtime $sb->atime;}