Tommy Nordgren wrote: > What's wrong with this script for removing the CVS directories from a > checked-out CVS workspace?
Are you asking because it is not working correctly? > #!/usr/bin/perl > use strict; > use warnings; > > my $mypath = '/Users/emac/gcc'; > > removecvs( $mypath); > > sub removecvs { > > my $path = $_[0]; > > system ('/bin/rmdir',"$path/CVS") or die "Can't remove CVS Directory $!"; system() returns "false" on success and "true" on failure so you want to use: system '/bin/rmdir', "$path/CVS" and die "Can't remove CVS Directory $?"; Or: system( '/bin/rmdir', "$path/CVS" ) == 0 or die "Can't remove CVS Directory $?"; But why not just use Perl's built-in rmdir() function: rmdir "$path/CVS" or die "Can't remove CVS Directory $!"; > my $dir; > > opendir($dir,$path); You should *ALWAYS* verify that the directory opened correctly: opendir my $dir, $path or die "Cannot open '$path' $!" > while (defined(my $file = readdir($dir))) { > next if ( ($file eq '.') or ($file eq '..')) ; > if (-d "$path/$file") { > removecvs("$path/$file"); > } > } > > closedir $dir; > } I would probably do something like this: #!/usr/bin/perl use strict; use warnings; use File::Find; my $mypath = '/Users/emac/gcc'; my @directories; find sub { -d and $_ eq 'CVS' and push @directories, $File::Find::name }, $mypath; for my $path ( @directories ) { rmdir $path or die "Can't remove '$path' $!"; } __END__ Also, your code will only remove "$path/CVS" if it is empty. If you want to remove a "$path/CVS" that contains files you should use the rmtree() function from the File::Path module. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>