Jayashankar Nelamane Srinivasarao wrote: > > Hi All Hello,
> Please tell me how to proceeed. I have been successfull with writing > the script for going through the directory and executing a command. > > But I have tried in vain to modify this code to be able to > recursively run the command through the whole sub-directories, whichever is > there. > > The following is the code I have started. Is this the right approach are > is there any simpler way of browsing through the directories. > > #TEMPLATE TO BROWSE THROUGH A DIRECTORY STRUCTURE > $rootdir="C:/Temp/Test/"; > chdir($rootdir); > > #We are in /1/@ > opendir(DIR1,$rootdir); > > @dirfirstlevel=readdir(DIR1); > > shift(@dirfirstlevel); > shift(@dirfirstlevel); > foreach $directory (@dirfirstlevel) > { > if(-d $directory) > { > `copy $directory $directory.bak`; > print "$directory\n"; > > } > } > > This code however assumes that the directory tree is fixed. How do I > do this when I do not know the depth of the directory C:/Temp/Test > > I would like to copy all the subdirectories under C:/Temp/Test to .bak Wow, that's a LOT of copying. :-) You should probably use File::Find use warnings; use strict; use File::Find; my $rootdir = 'C:/Temp/Test'; my @dirs; find( sub { -d and # is it a directory? !/^\.\.?$/ and # don't want . and .. directories push @dir, $File::Find::name }, $rootdir ); for my $dir ( @dirs ) { next if -e $dir; system( 'copy', $dir, "$dir.bak" ) == 0 or die "Cannot copy: $?"; print "$dir\n"; } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]