We have a cloning script, which can clone an entire folder and ceate a new folder. All the folders within folder and files within them are all created in new folder(recursive cloning). Now in the following code section of the entire script, we have made some changes to accommodate a requirement. Requirement was "Some of the files contain logo of site (a top level folder under workarea), which was named as logo-SiteA Now when we clone a site (folder), we have to give this a new name, say SiteB. Now the logo, which has also been cloned from previous siteA is to be renamed as logo-SiteB."
Following code is added to the existing to rename logo automatically in all the files of a cloned Site.
[html]sub copy_recursively {
my ($from_dir,$to_dir) =
@_;
opendir(DIR, $from_dir) or die "Could not open dir '$f
+rom_dir': $!";
my
@dir = readdir(DIR);
for(my $j=2 ; $j <= $#dir; $j++){
my $source = "$from_dir/$dir[$j]";
my $destination = "$to_dir/$dir[$j]";
next if($dir[$j] eq "." || $dir[$j] eq "..");
if (-d $source) {
print LOG "The source and destination in the d
+irectory section :-\n $source and $destination\n";
mkdir($destination,"0777") or die "mkdir '$des
+tination' failed: $!" if not -e $destination;
copy_recursively($source, $destination);
} else {
print LOG "The source and destination in t
+he File section :-\n $source and $destination\n";
open(FILE,"<", $source);
my
@file_content = ;
close(FILE);
for(my $u=0;$u<=$#file_content;$u++)
{
$file_content[$u] = s/logo-$source_bra
+nch/logo-$cloneName/g ;
print LOG "$file_content[$u]";
}
open(FILEOUT,">", $destination);
for(my $v=0;$v<=$#file_content;$v++)
{
print FILEOUT "$file_content[$v]";
}
[/html]When I have not added this piece of code, all the content in files come up perfect and the name of the logo remains same. But when I run the script with this piece of code, none of the file gets populated with any content in the cloned site and all the files are zero size files. What is the reason that cloned files are not getting populated with content from files of old site ? Also note that all the sub folders and files within them are getting cloned. Its the content in files that is not getting cloned.
Problem seems to be with the piece of code and the way files are opened, arrayed and written back.
Please correct me , if there is something wrong in the code.
Thanks