php 文件夹遍历俩种对比

configu.php
index.php
新建文件夹



D:\xampp\htdocs\1test\use\useversion/configu.php
D:\xampp\htdocs\1test\use\useversion/index.php
D:\xampp\htdocs\1test\use\useversion/mmmmmmmmmmm/configu2222222222222.php



D:\xampp\htdocs\1test\use\useversion/configu.php
D:\xampp\htdocs\1test\use\useversion/index.php
D:\xampp\htdocs\1test\use\useversion/mmmmmmmmmmm/configu2222222222222.php
D:\xampp\htdocs\1test\use\useversion/新建文件夹


代码:

<?php
function getDir($dirname) {
global $num;
$dh = opendir($dirname);
while (($file = readdir($dh)) !== false) {

if($file != '.' && $file != '..') {
if(is_dir($dirname . $file . '/'))
getDir($dirname . $file . '/');
else {echo $file.'<br/>';}
}}}
getDir("./useversion");
echo "<hr/>";

?>

<?php
function myscandir($pathname){

foreach( glob($pathname) as $filename ){

if(is_dir($filename)){
myscandir($filename.'/*');
}else{
echo '<br>'. $filename;
}
}
}

myscandir('D:\xampp\htdocs\1test\use\useversion');
echo "<hr/>";
?>
<?php

function myscandir2($path){

$mydir=dir($path);

while($file=$mydir->read()){
$p=$path.'/'.$file;
if((is_dir($p)) AND ($file!=".") AND ($file!="..")){
myscandir2($p);
}
if(($file!=".") AND ($file!="..")){
echo '<br>'. $p;
}


}
}
myscandir2('D:\xampp\htdocs\1test\use\useversion');
echo "<hr/>";
?>

 

posted @ 2014-09-12 09:41  也许明天  阅读(620)  评论(0编辑  收藏  举报