abhi_perl has asked for the wisdom of the Perl Monks concerning the following question:
Hi Friends,
I am new to perl. I am trying to work on a perl script which will delete only those files on a particular path which are older than 7 days in terms of accessed date of the files. However, it seems not working. But, when i put a condition "M" it does work for a modified date condition. Below is the code. Please suggest what should I do. Thanks for your help and suggestion.
#!/usr/local/bin/perl-w my $username = getlogin; my $userpath = "C:/Users/$username/AppData/Local/Temp/Data"; print $username; opendir (DIR, "$userpath") || die ("Unable to open directory"); @files=readdir(DIR); closedir(DIR); foreach $file (@files) { if (-A "$userpath/$file" > 7) { print ("$file\n"); print $userpath."/".$file; unlink $userpath."/".$file; print "File deleted successfully\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Script to delete only those files on a path whose accessed date is more than 7 days
by Athanasius (Archbishop) on Aug 13, 2012 at 08:08 UTC | |
by abhi_perl (Initiate) on Aug 13, 2012 at 13:49 UTC | |
|
Re: Script to delete only those files on a path whose accessed date is more than 7 days
by aitap (Curate) on Aug 13, 2012 at 08:11 UTC | |
|
Re: Script to delete only those files on a path whose accessed date is more than 7 days
by Anonymous Monk on Aug 13, 2012 at 08:29 UTC |