in reply to A couple of problems....
} else { open(ERRLOG, ">>$errorlog") or warn "scrapping error output\n"; + eval { die "($!)"; }; if ($@) { print ERRLOG "Cannot delete dir $_ : $@!\n"; } }
#!/usr/bin/perl -w use strict; use File::stat; use File::Find qw(finddepth); my($create_date, $current_date, $time_month, $month_old); my($dir,$dirs,$logfile,$logfile2,$errorlog); $_ = *File::Find::name; $month_old = 2592000; $current_date = time; $dir = 'd:\data\Transfer'; $logfile = 'd:\data\log.txt'; $logfile2 = 'd:\data\log_keep.txt'; $errorlog = 'd:\data\errorlog.txt'; finddepth \&deletion, $dir; # # Start of my function 'deletion' # sub deletion { if (-f) { $create_date = stat($_)->ctime; if ($create_date < ($current_date - $month_old)) { if (unlink ($_)) { open(LOG, ">>$logfile") or warn "discarding logfile output +\n"; print LOG "FIle: $_ - has been deleted.\n"; close (LOG) or warn "Can't close $logfile: $!"; } else { open(ERRLOG, ">>$errorlog") or warn "scrapping error outpu +t\n"; eval { die "($!)"; }; if ($@) { print ERRLOG "Cannot delete file $_ : $@!\n"; } } } else { open(LOG, ">>$logfile2") or warn "discarding logfile output\n" +; print LOG "The file $_ is newer than 30 days.\n"; close(LOG) or warn "Can't close $logfile2: $!"; } } else { $create_date = stat($_)->ctime; if ($create_date < ($current_date - $month_old)) { if (rmdir ($_)) { open(LOG, ">>$logfile") or warn "discarding logfile output +\n"; print LOG "Directory: $_ - has been deleted.\n"; close (LOG) or warn "Can't close $logfile: $!"; } else { open(ERRLOG, ">>$errorlog") or warn "scrapping error outpu +t\n"; eval { die "($!)"; }; if ($@) { print ERRLOG "Cannot delete dir $_ : $@!\n"; } } } else { open(LOG, ">>$logfile2") or warn "discarding logfile outpu +t\n"; print LOG "The dir $_ is newer than 30 days.\n"; close(LOG) or warn "Can't close $logfile2: ($!)"; } } }
|
|---|