<?php // $ignoreDir = ['.git', '.idea', 'vendor', '.vscode', 'logs', 'uploads', 'static', 'public']; $ignoreDir = ['.git', '.idea', '.vscode']; $OutPutString = ""; function loopDir($dir) { global $ignoreDir; global $OutPutString; static $level = 0; $handle = opendir($dir); while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { $str = ''; for ($i = 0; $i < $level; $i++) { $str .= ' '; } if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) { if (!in_array($file, $ignoreDir)) { $OutPutString .= $str . ($level > 0 ? ' - ' : '- ') . $file . PHP_EOL; ++$level; loopDir($dir . DIRECTORY_SEPARATOR . $file); } } } } $level--; closedir($handle); } loopDir(__DIR__); echo '<pre>'.$OutPutString.'</pre>';
效果:
- License - css - js - static - css - js - jquery