mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-06-07 20:48:09 +08:00
fix: 优化目录清理函数
This commit is contained in:
parent
aa6b383313
commit
d8b984b2dc
@ -71,10 +71,15 @@ class ToolsExtend
|
|||||||
*/
|
*/
|
||||||
public static function removeEmptyDirectory(string $path): bool
|
public static function removeEmptyDirectory(string $path): bool
|
||||||
{
|
{
|
||||||
foreach (self::findFilesYield($path, null, null, true) as $item) {
|
$dirs = [$path];
|
||||||
($item->isFile() || $item->isLink()) ? unlink($item->getPathname()) : rmdir($item->getPathname());
|
iterator_to_array(self::findFilesYield($path, null, function (SplFileInfo $file) use (&$dirs) {
|
||||||
}
|
$file->isDir() ? $dirs[] = $file->getPathname() : unlink($file->getPathname());
|
||||||
return is_file($path) ? unlink($path) : (!is_dir($path) || rmdir($path));
|
}));
|
||||||
|
usort($dirs, function ($a, $b) {
|
||||||
|
return strlen($b) <=> strlen($a);
|
||||||
|
});
|
||||||
|
foreach ($dirs as $dir) rmdir($dir);
|
||||||
|
return !file_exists($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user