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 <hnews@harvest-lodge.demon.co.uk> wrote in article
<880492908.29258.0.nnrp-02.c2de48f0@news.demon.co.uk>...
> 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
> Hugh@harvest-lodge.demon.co.uk

#!/bin/sh

TOP_DIR=/home/hugh/temp_files

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:

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

James Richardon
>


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



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