This article mainly introduces the PHP directory traversal method. The example summarizes two commonly used implementation techniques, which has certain reference value. Friends in need You can refer to the following
The example in this article summarizes the PHP directory traversal method. Share it with everyone for your reference. The details are as follows:
1. Method 1
?
3 4
5
6
9 10 11 |
function myscandir($pathname){
foreach( glob($pathname) as $filename ){
if(is_dir($filename)){
myscandir($filename.'/*');
}else{
echo $filename.' '; } } } myscandir('D:/wamp/www/exe1/*'); ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<🎜>function myscandir($path){<🎜>
<🎜>$mydir=dir($path);<🎜>
<🎜>while($file=$mydir->read()){
$p=$path.'/'.$file;
if(($file!=".") AND ($file!="..")){
echo $p.' '; } if((is_dir($p)) AND ($file!=".") AND ($file!="..")){ myscandir($p); } } } myscandir(dirname(dirname(__FILE__))); ?> |