DanNeedles has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm away from home and away from my toolbox of code. (Annoyingly enough I've written this exact program two years ago.) Anyway, I need a program to recursively march through a directory structure and removed files either based on a timestamp of creation or based on the naming convention. I know this has been done a million times and thought I'd ask before I reinvent the wheel. Is there anyone who can point me to some code that I can modify for these purposes? Thanks!!
  • Comment on Pruning of file with timestamps filenames

Replies are listed 'Best First'.
Re: Pruning of file with timestamps filenames
by blakem (Monsignor) on Sep 11, 2001 at 00:58 UTC
(tye)Re: Pruning of file with timestamps filenames
by tye (Sage) on Sep 11, 2001 at 01:05 UTC

    I'd use find2perl myself.

            - tye (but my friends call me "Tye")
      Actually, if asked to do this myself, I would use plain old GNU find. The other two suggestions are more in the spirit of Perl Monks, but neither have significant advantages over the find utility for this particular question.

      -Blake

        Actually, if asked to do this myself, I would use plain old GNU find. [...] but neither have significant advantages over the find utility for this particular question.

        Actually, there are several advantages of doing this type of thing with Perl instead of the regular "find" command. First, you can do it all in a single process. Second, you don't have to worry whether your "find" and "xargs" support "-print0" and "-0" nor remember to use them and yet your Perl code will not do dangerous things in the face of files with whitespace in their names. Third, Perl code is easier to extend in interesting ways when the desire hits.

        But my point about find2perl is that you can use it to generate the first version of the script and then just update that script in the future. Or use it to generate a template then edit it so that it takes the variable bits from the command line or even prompts for them (this is what I meant about being easy to extend in interesting ways).

                - tye (but my friends call me "Tye")