Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.


In reply to (Dermot) Re: Removing files with extentions of log and date-time. by Dermot
in thread Removing files with extentions of log and date-time. by curtisb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (4)
    As of 2020-11-29 02:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?