$ignoreDir = ['.git', '.idea', 'vendor', '.vscode', 'logs', 'uploads', 'static', 'public'];
function loopDir($dir)
{
global $ignoreDir;
static $level = 0;
$handle = opendir($dir);
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
$str = '';
for ($i = 0; $i
$str .= ' ';
}
if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
if (!in_array($file, $ignoreDir)) {
echo $str . ($level > 0 ? ' - ' : '- ') . $file . PHP_EOL;
++$level;
loopDir($dir . DIRECTORY_SEPARATOR . $file);
}
}
}
}
$level--;
closedir($handle);
}
loopDir('E:/GitServer/Ank');
输出如下