curtisb has asked for the wisdom of the Perl Monks concerning the following question:
Does anyone have any suggestions to what the problem might be?#!/usr/bin/perl -ws use strict; use Cwd; my $mode; &op; &scandir('c:\\mydocu~1'); sub op { if (defined @ARGV && $ARGV[0] =~ m/-all/) { $mode="all"; }else{ $mode="none"; } } sub scandir { my ($workdir) = shift || die "No working directory set: $!\n"; 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($file); 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!, All script\n"; } } } elsif ($mode eq "none") { if(-d $file) { &scandir($file); next; } if (-f $file) { if($file =~ m/\.\d+\w+\-\d+\wm$/i) { unlink($file) || warn "Unable to delete: $workdir\/$fi +le: $!\n"; }else{ print "No files to delete!, None script\n"; } } } chdir($startdir) || die "Unable to change to $startdir: $!\n"; } } &scandir(".");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Still problems with recursive coding.
by merlyn (Sage) on Nov 13, 2000 at 20:23 UTC | |
|
Re: Still problems with recursive coding.
by curtisb (Monk) on Nov 13, 2000 at 20:27 UTC | |
by jima (Vicar) on Nov 13, 2000 at 20:32 UTC | |
by Fastolfe (Vicar) on Nov 13, 2000 at 20:43 UTC | |
by curtisb (Monk) on Nov 14, 2000 at 02:34 UTC | |
by Fastolfe (Vicar) on Nov 14, 2000 at 02:38 UTC | |
by curtisb (Monk) on Nov 14, 2000 at 02:41 UTC |