本篇文章介绍开发和面试中经常遇见的问题,递归的遍历一个文件夹,以备日后需要是查看:
function getDir($path){
if(is_dir($path)){
foreach (scandir($path) as $afile){
if($afile == '.' || $afile=='..') continue;
if(is_dir($path.DIRECTORY_SEPARATOR.$afile)){
getDir($path.DIRECTORY_SEPARATOR.$afile);
}else{
echo $path.DIRECTORY_SEPARATOR.$afile.'<br>';
}
}
}else{
echo $path.'<br>';
}
}