本文实例总结了php遍历目录方法。分享给大家供大家参考。具体如下:
1. 方法1
1
2
3
4
5
6
7
8
9
10
11
12
|
<?php
function myscandir( $pathname ){
foreach ( glob ( $pathname ) as $filename ){
if ( is_dir ( $filename )){
myscandir( $filename . '/*' );
} else {
echo $filename . '<br/>' ;
}
}
}
myscandir( 'D:/wamp/www/exe1/*' );
?>
|
2. 方法2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<?php
function myscandir( $path ){
$mydir =dir( $path );
while ( $file = $mydir ->read()){
$p = $path . '/' . $file ;
if (( $file != "." ) AND ( $file != ".." )){
echo $p . '<br>' ;
}
if (( is_dir ( $p )) AND ( $file != "." ) AND ( $file != ".." )){
myscandir( $p );
}
}
}
myscandir(dirname(dirname( __FILE__ )));
?>
|
希望本文所述对大家的php程序设计有所帮助。