Update ToolsExtend.php

This commit is contained in:
邹景立 2024-09-10 09:47:48 +08:00
parent 1b78f1bd28
commit 752680a7cc

View File

@ -107,14 +107,14 @@ class ToolsExtend
*/
public static function findFilesArray(string $path, ?Closure $filterFile = null, ?Closure $filterPath = null, bool $short = true, ?int $depth = null): array
{
$files = [];
if (is_file($path)) {
if (($file = new SplFileInfo($path)) && ($filterFile === null || $filterFile($file))) {
$files[] = $short ? $file->getBasename() : $file->getPathname();
[$info, $files] = [new SplFileInfo($path), []];
if ($info->isFile()) {
if ($filterFile === null || $filterFile($info)) {
$files[] = $short ? $info->getBasename() : $info->getPathname();
}
} elseif (is_dir($path)) {
foreach (static::findFilesYield($path, $filterFile, $filterPath, $depth) as $file) {
$files[] = $short ? substr($file->getRealPath(), strlen($path) + 1) : $file->getRealPath();
} elseif ($info->isDir()) {
foreach (static::findFilesYield($info->getPathname(), $filterFile, $filterPath, $depth) as $file) {
$files[] = $short ? substr($file->getRealPath(), strlen($info->getPathname()) + 1) : $file->getRealPath();
}
}
return $files;