/** * Delete the filesystem object if it exists. * Directories will only be deleted if they're empty or if the $recursive param is set to true. * * @param resource $context [optional] See the unlink() function for documentation. * @param bool $recursive [optional] True to delete directories recursively. * This option should be true if directories with contents should be deleted. * * @return int Number of deleted filesystem objects, a negative number will be returned if the $path param was * invalid. * * @see unlink() */ public function delete($context = null, $recursive = false) { return FilesystemObjectHelper::delete($this, $recursive, $context); }
public static function copy($source, $destination, $overwrite = false, $context = null) { // Convert $oldPath and $newPath into an absolute oldPath string, return false on failure if (($source = self::getAbsolutePath($source)) === null) { return false; } if (($destination = self::getAbsolutePath($destination)) === null) { return false; } // Make sure the old oldPath exists, and the new oldPath is valid if (!self::exists($source) || !self::isValid($destination)) { return false; } // Make sure the new oldPath may be overwritten if it already exists if (self::exists($destination) & !$overwrite) { return false; } // Check whether a symbolic link must be copied if (self::isSymbolicLink($source)) { // Delete the filesystem object that will be overwritten before copying the object if (FilesystemObjectHelper::exists($destination)) { if (FilesystemObjectHelper::delete($destination, true) <= 0) { return false; } } // Read the newPath of the symlink $link = SymbolicLink::asSymbolicLink($source); // Create the new symbolic link, and make sure it was made successfully return SymbolicLinkHelper::createSymbolicLink($link->getTarget(), $destination) !== null; } // Copy the object, return the result if ($context !== null) { return copy($source, $destination, $context); } return copy($source, $destination); }