diff options
Diffstat (limited to 'util')
-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 ); +} |