copy() public méthode

Destination path supplied by user resolved to real destination path with {@link resolveDestPath}
public copy ( string $dest ) : CFile | boolean
$dest string Destination path for the current filesystem object to be copied to
Résultat CFile | boolean New CFile object for newly created filesystem object on success, 'False' on fail.
Exemple #1
0
 public function testCopy()
 {
     // A file.
     $filePath0 = CFile::createTemporary();
     $filePath1 = CFile::createTemporary();
     CFile::write($filePath0, "Hello there!");
     CFile::copy($filePath0, $filePath1);
     $this->assertTrue(CFile::exists($filePath0) && CFile::exists($filePath1) && CFile::read($filePath1)->equals("Hello there!"));
     CFile::delete($filePath0);
     CFile::delete($filePath1);
     // A directory.
     $directoryPath0 = CFilePath::add(CSystem::temporaryFilesDp(), CFile::DEFAULT_TEMPORARY_FILE_PREFIX . self::$ms_tempDirName);
     if (CFile::exists($directoryPath0)) {
         CFile::deleteDirectoryRecursive($directoryPath0);
     }
     CFile::createDirectory($directoryPath0);
     CFile::create(CFilePath::add($directoryPath0, "file-a3"));
     CFile::create(CFilePath::add($directoryPath0, "file-a20"));
     CFile::create(CFilePath::add($directoryPath0, "file-a100"));
     $directoryPath0Sub0 = CFilePath::add($directoryPath0, "dir-a2");
     $directoryPath0Sub1 = CFilePath::add($directoryPath0, "dir-a10");
     CFile::createDirectory($directoryPath0Sub0);
     CFile::create(CFilePath::add($directoryPath0Sub0, "file-a2"));
     CFile::create(CFilePath::add($directoryPath0Sub0, "file-a10"));
     CFile::createDirectory($directoryPath0Sub1);
     CFile::create(CFilePath::add($directoryPath0Sub1, "file-a2"));
     CFile::create(CFilePath::add($directoryPath0Sub1, "file-a10"));
     $directoryPath1 = "{$directoryPath0}-copy";
     if (CFile::exists($directoryPath1)) {
         CFile::deleteDirectoryRecursive($directoryPath1);
     }
     CFile::copy($directoryPath0, $directoryPath1);
     $this->assertTrue(CFile::exists($directoryPath1));
     $paths = CFile::listItemsRecursive($directoryPath1);
     $comparator = function ($arrayString, $findString) {
         return $arrayString->endsWith($findString);
     };
     $this->assertTrue($paths->length() == 9);
     $this->assertTrue($paths->find("/file-a3", $comparator) && $paths->find("/file-a20", $comparator) && $paths->find("/file-a100", $comparator) && $paths->find("/dir-a2", $comparator) && $paths->find("/dir-a10", $comparator) && $paths->find("/dir-a2/file-a2", $comparator) && $paths->find("/dir-a2/file-a10", $comparator) && $paths->find("/dir-a10/file-a2", $comparator) && $paths->find("/dir-a10/file-a10", $comparator));
     CFile::deleteDirectoryRecursive($directoryPath0);
     CFile::deleteDirectoryRecursive($directoryPath1);
 }