function readDirFiles($dir){
    $files= [];
    $queue=[realpath($dir)];

    $currentPath = current($queue);
    while($currentPath) {
        $path = $currentPath;
        if (is_dir($path) && $handle = opendir($path)) {
            while ($file = readdir($handle)) {
                if ($file == '.' || $file == '..') continue;

                $filepath = $path . '/' . $file;

                if (is_dir($filepath)) {
                    $queue[] = $filepath;
                }else {
                    $files[] = $filepath;
                }
            }

            closedir($handle);
        }

        $currentPath = next($queue);
    }

    return $files;
}

print_r($readDirFiles('./'));exit;

function readDirFiles2($path, &$files = []){
    if (is_dir($path) && $handle = opendir($path)) {
        while ($file = readdir($handle)) {
//            if(strpos($file, '.') === 0) {
//                continue;
//            }
            if ($file == '.' || $file == '..') continue;

            $filePath = $path . '/' . $file;

            if (is_dir($filePath)) {
                readDirFiles2($filePath, $files);
            }else {
                $files[] = $filePath;
            }
        }

        closedir($handle);
    }

    return $files;
}

readDirFiles2('./', $paths);
print_r($paths);exit;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2021-07-29
  • 2021-11-16
  • 2021-11-10
  • 2022-12-23
猜你喜欢
  • 2022-01-29
  • 2022-12-23
  • 2021-09-27
  • 2021-08-02
  • 2021-10-17
  • 2022-12-23
相关资源
相似解决方案