in reply to Logging deleted files
use strict; use warnings; use File::Find::Rule qw( ); use POSIX qw( strftime ); { my $ts = strftime('[%Y/%m/%d %H:%M:%S]', localtime()); my @files = File::Find::Rule->file() ->name('some_file_x') ->mtime('>' . 7*24*60*60) ->in('in_some_dir'); foreach my $file (@files) { if (unlink($file)) { print("$ts Deleted $file\n"); } else { print("$ts Failed to delete $file\n"); } } }
You could limit the number of changes by having the find tool simply print out a list of filenames to delete, then pipe the result to Perl to do the unlink and print.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Logging deleted files
by ikegami (Patriarch) on Oct 17, 2007 at 21:49 UTC | |
|
Re^2: Logging deleted files
by Bloodnok (Vicar) on Oct 18, 2007 at 13:22 UTC |