Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

(Dermot) Re: Removing files with extentions of log and date-time.

by Dermot (Scribe)
on Oct 08, 2000 at 17:10 UTC ( #35808=note: print w/replies, xml ) Need Help??


in reply to Removing files with extentions of log and date-time.

You want to delete all files in a specific directory with some exceptions. The exceptions are based around the filename.

Your general approach seems fine. One comment is that the regular expressions to allow the execeptions to the delete are probably not doing what you think they are. I assume that you wish to leave all files with a ".log" or ".datetime" or ".txt" extension. If that is so you should stop using the ^ at the start of the regular expression as this binds the regular expression to the start of the line (in this case a line is equivalent to a filename). This will only allow filenames called ".log" and ".txt" to remain whereas you would like "file.log" and "file.txt" to remain.

I'm not sure that your date/time regular expression is correct either but we would need to know the date/time format. Could you please post the date/time format being used and we can then check your regular expression.

So, in summary, drop the caret which is forcing the regular expression to match at the start of the line and the script should work as you intended.

Update: Just now noticed the !~ so invert the sense or what I said above as you want to delete the log/txy/datestamp files and leave all the rest. Yes, that does make more sense.

  • Comment on (Dermot) Re: Removing files with extentions of log and date-time.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2020-10-22 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (229 votes). Check out past polls.

    Notices?