in reply to Cleaning up by age
That could be used in conjunction with File::Find like so...unlink(@files[0..9]);
#!/usr/bin/perl -w use strict; use File::Find; my %age = (); my $dir = $shift; find(\&getFileAge, $dir); # Sort the values of %age my @files = sort {$a <=> $b} keys %age; # Remove the files foreach (@files[0..9]) {print qq($age{$_} $_\n);} # DEBUG - prints val +ues unlink @files[0..9] || warn "Couldn't remove $_\n"; # Removes files sub getFileAge() { # This gives you the full path of the file without # having to append the dir name my $element = $File::Find::name; if (-f $element) { my $temp_age = -M $element; $age{$temp_age} = $element; } }
|
|---|