Created
October 27, 2013 21:09
-
-
Save csharpforevermore/7187926 to your computer and use it in GitHub Desktop.
List the contents of a directory - by creation date. I use this script for when downloading large numbers of files and need to rename them later, although there are many other uses of course.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.12.0; | |
use warnings; | |
use File::stat; | |
my $dir_name = shift; | |
if ( not defined $dir_name ) { | |
die qq(Usage: $0 <directory>); | |
} | |
opendir(my $dir_fh, $dir_name); | |
my @file_list; | |
while ( my $file = readdir $dir_fh) { | |
if ( $file !~ /^\./ ) { | |
push @file_list, "$dir_name/$file" | |
} | |
} | |
closedir $dir_fh; | |
say scalar @file_list; | |
for my $file (sort { | |
my $a_stat = stat($a); | |
my $b_stat = stat($b); | |
$a_stat->ctime <=> $b_stat->ctime; | |
} @file_list ) { | |
say "$file"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment