Beispiel #1
0
echo '<br/>';
echo '<br/>';
echo 'Create new directory';
echo '<br/>';
$newDirectoryPath = __DIR__ . '/tmp/target/move/';
$newDirectoryFileObject = new File($newDirectoryPath);
if (!$newDirectoryFileObject->isDir()) {
    $newDirectoryFileObject->mkdirs();
}
echo 'Copy file to target directory';
echo '<br/>';
$examplePath = __DIR__ . '/example.txt';
$exampleCopyPath = __DIR__ . '/tmp/target/';
$fileObject = new File($examplePath);
$fileObject->copy($exampleCopyPath);
$fileObject->rename('example_copy.txt');
echo 'Move copied file to a new directory';
echo '<br/>';
$exampleMovePath = __DIR__ . '/tmp/target/move/';
$fileObject->move($exampleMovePath);
$fileObject->rename('example_move.txt');
echo 'Moved File ' . $fileObject->getPathname() . ' do' . ($fileObject->exists() ? '' : ' not') . ' exist.';
echo '<br/>';
echo 'File is' . ($fileObject->isReadable() ? '' : ' not') . ' readable.';
echo '<br/>';
echo 'File is' . ($fileObject->isWritable() ? '' : ' not') . ' writeable.';
echo '<br/>';
echo 'File permission: ' . $fileObject->getPermission();
echo '<br/>';
echo '<br/>';
echo 'Remove file';
Beispiel #2
0
 /**
  * @depends     testExist
  * @return      void
  */
 public function testRename()
 {
     // create file
     $filePath = __DIR__ . '/tmp/example_rename_old.txt';
     if (!is_file($filePath)) {
         fclose(fopen($filePath, 'x'));
     }
     // remove renamed file
     $filePathNew = __DIR__ . '/tmp/example_rename_new.txt';
     if (is_file($filePathNew)) {
         unlink($filePathNew);
     }
     $fileObject = new File($filePath);
     $this->assertTrue($fileObject->isFile());
     $this->assertTrue($fileObject->isWritable());
     $this->assertTrue($fileObject->rename('example_rename_new.txt'));
     $this->assertEquals($filePathNew, $fileObject->getPathname());
     $this->assertTrue($fileObject->isFile());
     // create dir
     $filePath = __DIR__ . '/tmp/ExampleRenameOld';
     if (!is_dir($filePath)) {
         mkdir($filePath, 0777);
     }
     // remove renamed file
     $filePathNew = __DIR__ . '/tmp/ExampleRenameNew';
     if (is_dir($filePathNew)) {
         rmdir($filePathNew);
     }
     $fileObject = new File($filePath);
     $this->assertTrue($fileObject->isDir());
     $this->assertTrue($fileObject->isWritable());
     $this->assertTrue($fileObject->rename('ExampleRenameNew'));
     $this->assertEquals($filePathNew, $fileObject->getPathname());
     $this->assertTrue($fileObject->isDir());
 }