deleting old [ascii] pfiles

From: Edward Glamkowski (EGlamkowski@MATHEMATICA-MPR.COM)
Date: 11/26/97

Someone asked a while back about a perl script to delete old player
files.  A very similar question was just asked in comp.lang.perl.misc :)

Hugh <> wrote in article
> I am having difficulty writing an efficient script to delete all files
> in a preset directory over a certain age. If a file is older than 14
> days I want to delete it. There are likely to be upwards of a couple
> of thousand or so files in the directory. How is the best way to check
> the create dates and delete if appropriate. As I said there is no need
> to recurse subdirs as they won't exist. All files to be deleted will
> have a .ABC suffix, the routine should ignore files without this.
> Thanks
> Hugh



find $TOP_DIR -name '*.ABC' -mtime +14 -print | perl -nle 'unlink;'

(From the FAQ!!!!!)

Should do the trick.....

It will recurse if there are any sub directories

The 'all perl' way to do it would be something like:

foreach $file (grep(/\.ABC$/, readdir(MYDIR))) {
        unlink $file if -M $file > 14;

James Richardon

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/08/00 PST