Hi,
I am using File::Find and File::Copy to accomplish the following:
check a directory tree for all files that end in *.html and copy them to a
different directory, preserving the tree structure.
The following code works fine provided that all subdirectories already
exist. But is there a way to add the requirement "if the subdirectory does
not yet exist, create it?"
TIA,
Birgit Kellner
### first we find all files in all subdirectories of directory "$origdir"
which end in *.html and
### push them into an array
$origdir = "original directory which contains lots of subdirectories with
html-files";
$targetdir = "target directory into which all subdirectories with all
html-files are to be copied";
use File::Find;
use File::Copy;
find (\&wanted, $origdir);
sub wanted {
if ($File::Find::name =~ /\.html/) {
push (@files, $File::Find::name)
}
}
### now we copy all files stored in the array
### to $targetdir, preserving the subdirectory structure.
foreach $file (@files) {
### $destfile will be the copied file in subdir admin, $file the original
file in $origdir or one of its subdirectories
$file =~ m/($origdir)(.*\/)(.*)$/;
$file =~ /($origdir)(.*?)(^\S+\.html)/;
$destfile = "$targetdir$2$3"; #
copy ("$file", "$destfile") || die (print "can't copy");
push (@destfiles, $destfile);
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]