At the moment all the source files are found, which is brilliant but they dumped into the destination directory and I'm losing the directory structure.
Im going to change the code to append the destination varible with the current directory when copy() fails.
Im going to try the reg ex in the morning.Something like this $\/* to match the / at the end of the string. Then happy days.
#!/usr/local/bin/perl -W # force taint checks, and print warnings use strict; # install all three strictures use File::Copy; use File::Find; my $path = ""; #define full path to source folder my $newpath = ""; #define path to new folder my @Filenames; #recursively search $path for files opendir (ORIG , $path); @Filenames = readdir ORIG; closedir ORIG; $|++; # force output of buffer find (\&doCopy, $path); #Recursively search $path for files to copy sub doCopy { return if ! -f $File::Find::name; chdir($path) || die "cannot move to $path"; my $destFile = $newpath . $_; #print "\$destFile = $destFile\n"; copy( "$_" , "$destFile" ) or $path = $File::Find::dir ; #print "$_ cannot be copied $!. $File::Find::dir \n" ; }
In reply to Re^2: Copying files between directories. How can I improve this code.
by richill
in thread Copying files between directories. How can I improve this code.
by richill
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |