1. 程式人生 > >遍歷一個文件夾下面所有的文件和子文件夾

遍歷一個文件夾下面所有的文件和子文件夾

php文件夾操作

<?php 
//遍歷一個文件下的所有文件夾和子文件夾

$dir = ‘../bootstrap-3.3.7-dist‘;

function showdir($dir){
    $arr = array();
    if($hd = opendir($dir)){
        while($file = readdir($hd)){
            if($file !== ‘..‘ && $file !== ‘.‘){
                if(is_dir($dir.‘/‘.$file)){
                    $arr[$file] = showdir($dir.‘/‘.$file);
                }else{
                    $arr[] = $file;
                }
            }
        }
    }
    closedir($hd);
    return $arr;
}

print_r(showdir($dir));

?>


本文出自 “手掌上的陽光” 博客,請務必保留此出處http://xiaobai123.blog.51cto.com/11280470/1971296

遍歷一個文件夾下面所有的文件和子文件夾