1. 遍历目录下的所有文件夹和文件
方法1:
~~~
$rootDir = '/rootdir';
foreachDir($dir);
function foreachDir($targetDir){
if(is_dir($targetDir)){
$dirhandler = opendir($targetDir);
while(($fileName = readdir($dirhandler)) !== false){
if('.' == $fileName || '..' == $fileName || strpos($fileName, '.') === 0){
continue;
}
echo $targetDir.'/'.$fileName."<br/>";
foreachDir($targetDir.'/'.$fileName);
}
closedir($dirhandler);
}
}
~~~
方法2:
~~~
$rootDir = '/rootdir';
scanFile($dir);
function scanFile($targetDir){
if(is_dir($targetDir)){
$files = scandir($targetDir);
foreach ($files as $file){
if('.' == $file || '..' == $file || strpos($file,'.') === 0){
continue;
}
//echo $targetDir.'/'.$file.'</br>';
scanFile($targetDir.'/'.$file,$fileArr);
}
}
}
~~~