diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-02-14 14:52:32 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-02-14 14:52:32 +0800 |
commit | cdcb4833ed752e5fff610a924fb122c478175ecc (patch) | |
tree | 75c51ed1deb240ac830349fc2b49053cba17d3e3 | |
parent | 58dcec234e414c296b266822aaf880c92a86c5d2 (diff) | |
download | pttbbs-cdcb4833ed752e5fff610a924fb122c478175ecc.tar pttbbs-cdcb4833ed752e5fff610a924fb122c478175ecc.tar.gz pttbbs-cdcb4833ed752e5fff610a924fb122c478175ecc.tar.bz2 pttbbs-cdcb4833ed752e5fff610a924fb122c478175ecc.tar.lz pttbbs-cdcb4833ed752e5fff610a924fb122c478175ecc.tar.xz pttbbs-cdcb4833ed752e5fff610a924fb122c478175ecc.tar.zst pttbbs-cdcb4833ed752e5fff610a924fb122c478175ecc.zip |
add cleandir.pl
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1536 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | util/cleandir.pl | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/util/cleandir.pl b/util/cleandir.pl new file mode 100644 index 00000000..63b484e4 --- /dev/null +++ b/util/cleandir.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl +# $Id$ +use strict; +use BBSFileHeader; + +my($nDels, $prefix) = (); + +foreach( @ARGV ){ + print "cleaning: $_\n"; + cleandir($_); + print "\n"; +} + +sub toclean +{ + unlink("$prefix/$_[0]"); + print "$_[0]\t"; + ++$nDels; +} + +sub cleandir($) +{ + my($dir) = @_; + my(%files, %dotDIR, $now, $counter) = (); + $now = time(); + $prefix = $dir; + + opendir DIR, $dir; + foreach( readdir(DIR) ){ + if( /^M\.\d+\.A/ ){ + $files{$_} = 1; + } elsif( (/^SR\./) && (stat($_))[2] < ($now - 86400) ){ + toclean($_); + } + } + close DIR; + + tie %dotDIR, 'BBSFileHeader', $dir; + foreach( 0..($dotDIR{num} - 1) ){ + my $fn = $dotDIR{"$_.filename"}; + delete $files{$fn}; + } + untie %dotDIR; + + toclean($_) + foreach( keys %files ); +} |