1. 程式人生 > >php遞歸遍歷目錄

php遞歸遍歷目錄

function style code col pen open $path nbsp div

$path=‘./phpMyAdmin‘;

function showAll($path){
    if(is_dir($path)){
        $handle=opendir($path);
        //$file=readdir($handle);        為什麽不能在外面讀取目錄句柄
        echo "<ul>";        
        while(false !== ($file = readdir($handle))){
            if($file==‘.‘ ||$file==‘..‘){
                
continue; } echo "<li>".$file."</li>"; if(is_dir($path.‘/‘.$file)){ showAll($path.‘/‘.$file); } } echo "</ul>"; closedir($handle);//關閉目錄句柄 }else{ echo "不是目錄"; } } showAll(
$path);

php遞歸遍歷目錄