getFilename() === '.' || $file->getFilename() === '..') { continue; } if ($file->isDir()) { rmdir($file->getRealPath()); } else { unlink($file->getRealPath()); } } } /** * Copy files recursively. * * @param string $source * @param string $destination */ public static function copyRecursive($source, $destination) { if (!is_dir($destination)) { mkdir($destination); } $dir = opendir($source); if ($dir === false) { throw new RuntimeException("Cannot copy '$source' to '$destination'"); } while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($source . DIRECTORY_SEPARATOR . $file)) { static::copyRecursive( $source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file ); } else { copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); } } } closedir($dir); } }