一个困扰偶很久的目录遍历问题
前几天在做一个项目时用到了一个目录遍历问题。
看似简单,却花了偶近一天时间才搞定。
以下是我刚开始写的代码。大家能看出来是哪错了吗?:D
或者有兴趣的朋友也可以试试自己写写看。。
<?php
function Get($path,&$a) {
$handle = opendir($path);
while ($filename = readdir($handle)) {
if ($filename == "." || $filename == "..") continue;
if (is_dir($path."/".$filename)) {
$newpath = $path."/".$filename;
echo "<BR><BR><H2>目录".$filename."</H1><BR><BR>";
$a['d']++;
Get($newpath,&$a);
} else {
echo "<Normal>".$filename."</Normal>";
$a['f']++;
}
}
closedir($handle);
}
Get('c:/tmp',$count);
echo "共有目录{$count['d']}个,文件{$count['f']}个..."
?>