用队列的方式解决目录遍历问题

用队列的方式解决目录遍历问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public function ($path='.'){
$queue=array($path);
while (!empty($queue)) {
$currentPath=array_shift($queue);
$currentDir = dir($currentPath);
while (false !== ($filePath = $currentDir->read())) {
if( '.' == $filePath || '..' == $filePath ){
continue;
}
if(is_dir($currentPath.'/'.$filePath)){
array_push($queue, $currentPath.'/'.$filePath);
}
echo $currentPath.'/'.$filePath."n";
}
$currentDir->close();
}
}
getFiles('d:/software');
?>