From 6743119a4871decf7a542803cf5652296d1502d3 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Sat, 20 Aug 2016 12:52:35 +0000 Subject: [PATCH] file : copy can copy directory or files git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3000 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- file.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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; }