All,
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.
FROM LOCATION:
-rw-r--r-- 2 rc dev 3885052 Jun 30 2003 setup.jar
-rwxr-xr-x 2 rc dev 15908537 Jun 30 2003 setup.SunOS.bin
-rwxr-xr-x 2 rc dev 10686224 Jun 30 2003 setup.exe
-rwxr-xr-x 2 rc dev 29097226 Jun 30 2003 setup.HP-UX.bin
-rwxr-xr-x 2 rc dev 17022276 Jun 30 2003 setup.AIX.bin
-rw-r--r-- 2 rc dev 149236605 Jun 30 2003 Server.jar
-rw-r--r-- 2 rc dev 7537725 Jun 30 2003 Web.jar
-rw-r--r-- 2 rc dev 1938577 Jun 30 2003 config.jar
AFTER COPYING :
-rw-r--r-- 1 rav orms 17022276 Jun 30 2003 setup.AIX.bin
-rw-r--r-- 1 rav orms 10686224 Jun 30 2003 setup.exe
-rw-r--r-- 1 rav orms 29097226 Jun 30 2003 setup.HP-UX.bin
-rw-r--r-- 1 rav orms 3885052 Jun 30 2003 setup.jar
-rw-r--r-- 1 rav orms 15908537 Jun 30 2003 setup.SunOS.bin
-rw-r--r-- 1 rav orms 149236605 Jun 30 2003 Server.jar
-rw-r--r-- 1 rav orms 1938577 Jun 30 2003 config.jar
-rw-r--r-- 1 rav orms 7537725 Jun 30 2003 Web.jar
*************************************
$ViewableDir = "/home/work/cdimage";
$copyDir = $ViewableDir;
find({wanted => \©DirRecursive, no_chdir => 1},'.');
$copyDir = undef;
*********************************
sub copyDirRecursive {
$File::Find::name =~ 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;
}
Thanks,
Ravi