From 4bc2fcaf6c31248acec74ebe179b7fbba1c06b11 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 25 Jul 2016 18:54:31 +0000 Subject: [PATCH] file : add rename and copy functions git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2956 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- file.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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