file : copy can copy directory or files

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3000 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-08-20 12:52:35 +00:00
parent 8d9c1340ba
commit 6743119a48

View File

@@ -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;
}