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/>";
?>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。