note 104809 added to function.copy
| From: | ravindersingh dot jal at gmailDELTHIS dot com | Date: | Fri, 08 Jul 2011 11:20:22 +0000 |
| Subject: | note 104809 added to function.copy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181349@lists.php.net to get a copy of this message | ||
I had to copy a directory but the top level folder name would be different at dest i.e.
dirparent/dirchild -> diff/dirchild . I thought I would just copy and rename the destination but
you can't rename non empty directories. I wrote this function to work around this:
function RecursiveCopy($source, $dest, $diffDir = ''){
$sourceHandle = opendir($source);
if(!$diffDir)
$diffDir = $source;
mkdir($dest . '/' . $diffDir);
while($res = readdir($sourceHandle)){
if($res == '.' || $res == '..')
continue;
if(is_dir($source . '/' . $res)){
RecursiveCopy($source . '/' . $res, $dest, $diffDir . '/' . $res);
} else {
copy($source . '/' . $res, $dest . '/' . $diffDir . '/' .
$res);
}
}
}
----
Server IP: 59.162.86.8
Probable Submitter: 119.82.121.194
----
Manual Page -- http://www.php.net/manual/en/function.copy.php
Edit -- https://master.php.net/note/edit/104809
Del: integrated -- https://master.php.net/note/delete/104809/integrated
Del: useless -- https://master.php.net/note/delete/104809/useless
Del: bad code -- https://master.php.net/note/delete/104809/bad+code
Del: spam -- https://master.php.net/note/delete/104809/spam
Del: non-english -- https://master.php.net/note/delete/104809/non-english
Del: in docs -- https://master.php.net/note/delete/104809/in+docs
Del: other reasons-- https://master.php.net/note/delete/104809
Reject -- https://master.php.net/note/reject/104809
Search -- https://master.php.net/manage/user-notes.php