use strict; use warnings; # Function to format a time: YYYY-MM-DD HH:MM:SS sub mydatetime { my $time = shift; my ($s, $m, $h, $d, $mon, $y) = localtime $time; sprintf "%04d-%02d-%02d %02d:%02d:%02d", $y+1900, $mon+1, $d, $h, $m, $s; } my $source_directory = 'E:\\common\compare\latest folder\PDF\DB\\'; # Read directory contents into array @paths. opendir my $dh, $source_directory or die "error: open '$source_directory': $!"; my @paths = grep { $_ ne '.' && $_ ne '..' } readdir $dh; closedir $dh; print "Contents of dir '$source_directory':\n"; for my $p (@paths) { my $fullpath = $source_directory . $p; my ($size, $modtime) = (stat $fullpath)[7,9]; my $type = -d $fullpath ? "directory" : "$size bytes"; printf "%-20.20s: %s (%s)\n", $p, mydatetime($modtime), $type; }