ellandrd
asked on
copy folder A and its contents to another folder B
i have a snippet of code that i need some help with. i want to copy folder A "core" and all its contents to folder B "<customer_name>".
so far my functions just copy files. it doesnt copy any subfolder files.
/public_html/xxx/cms/core/ <----------------- folder A is core. core contains 3 txt files and a sub folder called "includes" with 4 txt files .
/<customer_name>/public/xx x/ <-------------------- folder B is <customer_name> - the param i pass into my SetupCustomer function.
basically im copying everything inside core to a folder outside the public_html
see code below:
so far my functions just copy files. it doesnt copy any subfolder files.
/public_html/xxx/cms/core/
/<customer_name>/public/xx
basically im copying everything inside core to a folder outside the public_html
see code below:
function CopyCoreFiles($current_directory,$template_directory,$customer_directory)
{
$dots = array('.', '..');
$files = array_diff(scandir($template_directory), $dots);
foreach($files as $file)
{
chdir($template_directory);
$myfile = file_get_contents($file);
chdir($current_directory);
chdir($customer_directory);
file_put_contents($file,$myfile);
chdir($current_directory);
}
$files = array_diff(scandir($customer_directory), $dots);
if(count($files) > 0)
{
unset($files,$file,$dots,$myfile,$customer_directory,$template_directory,$current_directory);
return 1;
}
else
{
unset($files,$file,$dots,$myfile,$customer_directory,$template_directory,$current_directory);
return 0;
}
}
function SetupCustomer($customer_name)
{
$current_directory = '';
if(is_dir($customer_name))
{
$this->DeleteFolderAndFiles($customer_name.'/');
rmdir($customer_name);
}
mkdir($customer_name);
$current_directory = getcwd();
if($this->CopyCoreFiles($current_directory,'cms/core/',$customer_name) == 1)
{
unset($current_directory,$customer_name,$handle,$file,$current_directory);
return true;
}
else
{
unset($current_directory,$customer_name,$handle,$file,$current_directory);
return false;
}
}
SetupCustomer('pegasus');
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yes, it will. but you should do additional checks to be 100% sure, as i don't do any checkings ( if includes folder exists etc..)
ASKER
Looking at your code without testing it yet, will it copy all files inside core and its sub folder includes?