Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; die "Wrong Number of Arguments" unless $#ARGV == 1; $sourceDir = $ARGV[0]; $days = $ARGV[1]; #foreach $arg (@ARGV) { # print "one arg is $arg\n"; #} opendir source_DIR, $sourceDir or die "ERROR opening: $sourceDir, $!"; @sourceFiles = readdir source_DIR; closedir source_DIR; foreach $file ( @sourceFiles ) { # print( "sourceFiles $file \n" ); # next if -d $sourceDir . "\\" . $file if ($file eq '.') { # do nothing # print "working dir \n"; } else { if ($file eq '..') { # do nothing # print "parent dir \n"; } else { remove_dir( $sourceDir . "\\" . $file ) if -M $sourceDir . "\ +\" . $file >= $days; } } } # del_file # arg_0 = filename, including full path, to be deleted sub remove_dir { my $file = shift(@_); @args = ( 'rmdir /s /q' , $file ) ; print "system command: @args \n"; system( @args ) == 0 or die "error removing $file!"; } # End move_file
Edit: Added <code> tags. Fixed some formatting. larsen
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using NT - rmdir cmd to purge aged NT folders
by Albannach (Monsignor) on Aug 02, 2002 at 18:42 UTC | |
by fglock (Vicar) on Aug 02, 2002 at 19:08 UTC |