diff --git a/file.php b/file.php index f1e822f..e57960a 100644 --- a/file.php +++ b/file.php @@ -260,6 +260,42 @@ class file return $rc; } + /** Copy a file + * @param string $oldname The file to rename + * @param string $newname The new name of the file. It will be + * overwrited if it already exists + * @return bool + */ + public function copy ($oldname, $newname) + { + $this->debug (2, "copy ($oldname, $newname)"); + $oldname = $this->realpath ($oldname); + $newname = $this->realpath ($newname); + $this->checkPathRO (dirname ($oldname)); + $this->checkPathRW (dirname ($newname)); + $rc = copy ($oldname, $newname); + $this->debug (1, "copy ($oldname, $newname) => $rc"); + return $rc; + } + + /** Renames a file or directory + * @param string $oldname The file or directory to rename + * @param string $newname The new name of the file or directory. It will be + * overwrited if it already exists + * @return bool + */ + public function rename ($oldname, $newname) + { + $this->debug (2, "rename ($oldname, $newname)"); + $oldname = $this->realpath ($oldname); + $newname = $this->realpath ($newname); + $this->checkPathRO (dirname ($oldname)); + $this->checkPathRW (dirname ($newname)); + $rc = rename ($oldname, $newname); + $this->debug (1, "rename ($oldname, $newname) => $rc"); + return $rc; + } + /** Return a ini file converted to an array * @param string $filename The filename of the ini file being parsed. * @param bool $process_sections Process the sections