diff --git a/file.php b/file.php index 3b14462..9407088 100644 --- a/file.php +++ b/file.php @@ -260,8 +260,8 @@ class file return $rc; } - /** Copy a file - * @param string $oldname The file to rename + /** Copy a file or a directory + * @param string $oldname The file to copy * @param string $newname The new name of the file. It will be * overwrited if it already exists * @return bool @@ -273,7 +273,19 @@ class file $newname = $this->realpath ($newname); $this->checkPathRO (dirname ($oldname)); $this->checkPathRW (dirname ($newname)); - $rc = copy ($oldname, $newname); + if (is_dir ($oldname)) + { + // Copy directory structure + if (! $this->file_exists ($newname)) + $this->mkdir ($newname); + $files = $this->scandirNotSorted ($oldname); + foreach ($files as $file) + $this->copy ("$oldname/$file", "$newname/$file"); + } + else + { + $rc = copy ($oldname, $newname); + } $this->debug (1, "copy ($oldname, $newname) => $rc"); return $rc; }