<span style="font-size: 14px;">function dirTree(){<br> if(!is_dir($path)) return []; $files = []; $dir = opendir($path); while($file = readdir($dir)) { if($file == '.' || $file == '..') continue; $new_path = trim($path, '/').'/'.trim($file, '/'); $files[] = $new_path; if(is_dir($new_path)){ $files = array_merge($files, $this->ergodicDir2($new_path));<br> }<br> }<br> closedir($dir); return $files;<br>}<br></span>
<span style="font-size: 14px;">function dirTree(){<br> if(!is_dir($path)) return []; $files = []; $dir_h = dir($path); while($file = $dir_h->read()){ if($file == '.' || $file == '..') continue; $new_path = trim($path, '/').'/'.trim($file, '/'); $files[] = $new_path; if(is_dir($new_path)){ $files = array_merge($files, $this->ergodicDir3($new_path));<br> }<br> } $dir_h->close(); return $files;<br>}<br></span>
<span style="font-size: 14px;">function dirTree(){<br> if(!is_dir($path)) return []; $files = []; $dir = new \DirectoryIterator($path); foreach ($dir as $key => $file){ if($file->getFilename() == '.' || $file->getFilename() == '..'){ continue;<br> } $files[] = $file->getPathname(); if($file->isDir()){ $files = array_merge($files, $this->ergodicDir5($file->getPathname()));<br> }<br> } return $files;<br>}<br></span>
Recommandations associées :
Parcours de dossiers PHP, compression d'images dans des proportions égales
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!