Ravinder Arepally wrote: > > All, Hello,
> I am seeing weird problem while using File::Find to copy files and directory > recursively in a specified directory. > > What I am trying to do is : > > 1) I need to copy everything from a specified directory to a known location. > 2) It should copy even directories and files. > > I copied code and pasted at end of this mail from my script and it is > working fine. Problem I am seeing is with permissions it is > changing after copying files. I checked umask and it is 022. When I copy > using system command > "cp", I don't see this problem. Any help is greatly appreciated. > > [snip] > > -rwxr-xr-x 2 rc dev 15908537 Jun 30 2003 setup.SunOS.bin > > AFTER COPYING : > > -rw-r--r-- 1 rav orms 15908537 Jun 30 2003 setup.SunOS.bin Use stat() or lstat() to get the information from the old file and chmod(), chown() and utime() to change the new files. perldoc -f stat perldoc -f lstat perldoc -f chmod perldoc -f chown perldoc -f utime > ************************************* > $ViewableDir = "/home/work/cdimage"; > $copyDir = $ViewableDir; > find({wanted => \©DirRecursive, no_chdir => 1},'.'); > $copyDir = undef; If you want to limit the scope of $copyDir you should use a lexical variable. { my $copyDir = $ViewableDir; find( { wanted => \©DirRecursive, no_chdir => 1 }, '.' ); } > ********************************* > > sub copyDirRecursive { > > $File::Find::name =~ s/\.\///; Because you are using "no_chdir" $_ and $File::Find::name contain the same data and you want to remove './' from the beginning of the string only: s|^\./||; > my $file = $File::Find::name; > > if( -d $File::Find::name) { > if ( ! -e "$copyDir/$file") { > mkpath("$copyDir/$file") || die "Cannot mkdir $copyDir/$file : > $! \n"; > } > return; > } > copy("$file","$copyDir/$file") || die "Cannot copy $file to > $copyDir/$file :$! \n"; > return; > } sub copyDirRecursive { s|^\./||; return if /\A\.\.?\z/; my $file = "$copyDir/$_"; if( -d ) { if ( not -e $file ) { mkpath $file or die "Cannot mkdir $file: $!"; } else { copy $_, $file or die "Cannot copy $_ to $file: $!"; } my @stat = stat; chmod $stat[ 2 ] & 0777, $file or warn "Cannot chmod $file: $!"; chown @stat[ 4, 5 ], $file or warn "Cannot chown $file: $!"; utime @stat[ 8, 9 ], $file or warn "Cannot utime $file: $!"; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>