#!/usr/bin/perl -ws use strict; use Cwd; my $mode; &op; &scandir("C:/mydocu~1"); sub op { if (defined (@ARGV) $ARGV[0]=~/-all/) { $mode="all"; }else{ $mode=""; } } sub scandir { my ($workdir) = &scandir; my ($startdir) = &cwd; chdir($workdir) || die "Unable to change to $workdir: $!\n"; opendir(DIR, ".") || die "Unable to open $workdir: $!\n"; my @files = readdir(DIR) || die "Unable to read $workdir: $!\n"; closedir(DIR) || die "Unable to close $workdir: $!\n"; foreach my $file (@files) { next if ($file eq "."); next if ($file eq ".."); if ($mode eq "all") { if (-d $file) { &scandir; next; } if (-f $file) { if($file =~ m/\.\d+\w+\-\d+\wm$/i || $file =~ m/\.log$/i) { unlink($file) || warn "Unable to delete: $file: $!\n"; }else{ print "No files to delete!\n"; } } } elsif ($mode eq "") { if(-d $file) { &scandir; next; } if (-f $file) { if($file =~ m/\.\d+\w+\-\d+\wm$/i) { unlink($file) || warn "Unable to delete: $workdir\/$file: $!\n"; }else{ print "No files to delete!\n"; } } } chdir($startdir) || die "Unable to change to $startdir: $!\n"; } } &scandir(".");