Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Don't ask to ask, just ask
 
PerlMonks  

Re: Deleting files older then 48 hours..

by stefan k (Curate)
on Nov 12, 2001 at 18:40 UTC ( #124833=note: print w/ replies, xml ) Need Help??


in reply to Deleting files older then 48 hours..

Hi,
the first thing -of course- that comes to mind is that I would do this using the find command. One would use the mtime flag to set the (modification)time and would combine it with the name-checker (-name) to exclude blahblah.zip. Then pipe it into xargs rm -f and that's it.

But then you seem to want to do this in perl. Simply put a check into your loop:

foreach $file (<*.zip>) { next if $file =~ /blahblah/; # continue with filetype- and time-checking and # deletion... unless (-d $file) { # no dirs # use stat($file)[9] which is mtime in seconds, I # think, or use the -M filetest which gives days # to find out whether to delete or not... } }
(Please note the regexp test (/blahblah/) could be replaced by string equality ( eq "blahblah.zip") when you really(!) need performance, and please lookup the return values of -M and stat since I'm not really sure of it).

Maybe you should consider using File::Find for this...

Regards... Stefan
you begin bashing the string with a +42 regexp of confusion


Comment on Re: Deleting files older then 48 hours..
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://124833]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (14)
As of 2014-04-16 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (434 votes), past polls