mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-20 15:25:36 +08:00
Allow callback for removeDir
This commit is contained in:
@@ -287,10 +287,11 @@ class FileSystem
|
|||||||
/**
|
/**
|
||||||
* Remove directory recursively
|
* Remove directory recursively
|
||||||
*
|
*
|
||||||
* @param string $dir Directory to remove
|
* @param string $dir Directory to remove
|
||||||
* @return bool Success status
|
* @param null|callable $callback Callback for every single scan items
|
||||||
|
* @return bool Success status
|
||||||
*/
|
*/
|
||||||
public static function removeDir(string $dir): bool
|
public static function removeDir(string $dir, ?callable $callback = null): bool
|
||||||
{
|
{
|
||||||
$dir = self::convertPath($dir);
|
$dir = self::convertPath($dir);
|
||||||
logger()->debug('Removing path recursively: "' . $dir . '"');
|
logger()->debug('Removing path recursively: "' . $dir . '"');
|
||||||
@@ -311,7 +312,9 @@ class FileSystem
|
|||||||
}
|
}
|
||||||
// 遍历目录
|
// 遍历目录
|
||||||
foreach ($scan_list as $v) {
|
foreach ($scan_list as $v) {
|
||||||
InteractiveTerm::advance();
|
if ($callback) {
|
||||||
|
$callback($v);
|
||||||
|
}
|
||||||
// Unix 系统排除这俩目录
|
// Unix 系统排除这俩目录
|
||||||
if ($v == '.' || $v == '..') {
|
if ($v == '.' || $v == '..') {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user