Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursive - copy a directory, sub dir and files

Status
Not open for further replies.

cabernet

Technical User
Feb 24, 2003
75
0
0
PK
The following regards: PHP5 and Apache2

I cannot figure the proper scripting however as is it does not generate an error, just plain does nothing!

<?php
//error_reporting (E_ALL);

$dirsource="../tpl_for_dupli/calendar";
$dirdest="../chamber_members/calendar";

function COPY_RECURSIVE_DIRS($dirsource, $dirdest)
{
if(is_dir($dirsource))$dir_handle=opendir($dirsource);
mkdir($dirdest."/".$dirsource, 0750);
while($file=readdir($dir_handle))
{
if($file!="." && $file!="..")
{
if(!is_dir($dirsource."/".$file)) copy ($dirsource."/".$file, $dirdest."/".$dirsource."/".$file);
else COPY_RECURSIVE_DIRS($dirsource."/".$file, $dirdest);
}
}
closedir($dir_handle); return true;

}

thank you
 
I don't see any place you actually invoke the function.
There should be a call like:
Code:
COPY_RECURSIVE_DIRS($dirsource,$dirdest);
Could it be that simple?
 
Thank you,
It seems to be here:

if(!is_dir($dirsource."/".$file)) copy ($dirsource."/".$file, $dirdest."/".$dirsource."/".$file);
else COPY_RECURSIVE_DIRS($dirsource."/".$file, $dirdest);
 
PHP-manual said:
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}

/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}
You implemented what is called WRONG above.
 
Thank you

Well, I even did look at manual before posting! :)

that should indeed do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top