getPathname(); if (strpos($path_source, $source) !== 0) { continue; } if ($exclude_regexp && preg_match($exclude_regexp, $path_source)) { continue; } $path_destination = $destination . substr($path_source, strlen($source)); if ($path->isDir()) { $status = self::isDirectory($path_destination) || self::createDirectory($path_destination, $path->getPerms()); if (!$status) { return false; } } else { $status = self::copy($path_source, $path_destination, $path->getPerms()); if (!$status) { return false; } } } return true; } /** * Move a directory. * * @param string $source * @param string $destination * @return bool */ public static function moveDirectory($source, $destination) { return self::move($source, $destination); } /** * Delete a directory recursively. * * @param string $dirname * @param bool $delete_self (optional) * @return bool */ public static function deleteDirectory($dirname, $delete_self = true) { $dirname = rtrim($dirname, '/\\'); if (!self::isDirectory($dirname)) { return false; } $rdi_options = \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS; $rii_options = \RecursiveIteratorIterator::CHILD_FIRST; $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dirname, $rdi_options), $rii_options); foreach ($iterator as $path) { if ($path->isDir()) { if (!@rmdir($path->getPathname())) { return false; } } else { if (!@unlink($path->getPathname())) { return false; } } } if ($delete_self) { return @rmdir($dirname); } else { return true; } } }