mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-18 15:31:06 +08:00
Method "yii\helpers\base\FileHelper::removeDirectory()" has been added.
This commit is contained in:
@@ -169,4 +169,26 @@ class FileHelper
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a directory recursively.
|
||||
* @param string $directory to be deleted recursively.
|
||||
*/
|
||||
public static function removeDirectory($directory)
|
||||
{
|
||||
$items = glob($directory . DIRECTORY_SEPARATOR . '{,.}*', GLOB_MARK | GLOB_BRACE);
|
||||
foreach ($items as $item) {
|
||||
if (basename($item) == '.' || basename($item) == '..') {
|
||||
continue;
|
||||
}
|
||||
if (substr($item, -1) == DIRECTORY_SEPARATOR) {
|
||||
self::removeDirectory($item);
|
||||
} else {
|
||||
unlink($item);
|
||||
}
|
||||
}
|
||||
if (is_dir($directory)) {
|
||||
rmdir($directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user