1. Method One:
Copy Code code as follows:
?
$dir = "D:";
static $dir _list = 0;
static $file _list = 0;
function ListFile ($dir) {
Global $dir _list, $file _list;
$d = Dir ($dir);
while ($entry = $d->read ()) {
$tem _curnt= $dir. " /". $entry;
if ($entry = = "." | | $entry = = "...") Continue
if (Is_dir ($tem _curnt)) {
ListFile ($tem _curnt);
echo "folder". $tem _curnt. " <br> ";
$dir _list++;
}
ElseIf (Is_file ($tem _curnt)) {
echo "File". $tem _curnt. " <BR> ";
$file _list++;
}
}
$d->close ();
}
ListFile ($dir);
echo "Directory number:". $dir _list;
echo "<br>";
echo "Number of files:". $file _list;
?>
2. Method Two:
Copy Code code as follows:
<?php
function List_dir ($dirpath) {
if ($dirpath [strlen ($dirpath)]-1!= '/') {
$dirpath. = "/";
}
Static $result _array=array ();
if (Is_dir ($dirpath)) {
$files _dirs=scandir ($dirpath);
foreach ($files _dirs as $file) {
if ($file = = '. ' | | $file = = '.. ') {continue;}
if (Is_dir ($dirpath. $file)) {
List_dir ($dirpath. $file);
}else{
Array_push ($result _array, $dirpath. $file);
}
}
}
return $result _array;
}
$array =list_dir (' d:/www ');
foreach ($array as $value) {
Echo $value;
echo "<br>";
}
?>
3. Method Three:
Copy Code code as follows:
<?php
function List_dir ($dirpath) {
if ($dirpath [strlen ($dirpath) -1]!= "//") {$dirpath. = "//";}
Static $result _array=array ();
if (Is_dir ($dirpath)) {
$handle =opendir ($dirpath);
while ($file =readdir ($handle)) {
if ($file = = "." | | $file = = "...") {continue;}
if (Is_dir ($dirpath. $file)) {
List_dir ($dirpath. $file. " //");
}else{
Array_push ($result _array, $dirpath. $file);
}
}
Closedir ($handle);
}
return $result _array;
}
$array =list_dir ("d:/www");
foreach ($array as $value) {
Echo $value;
echo "<br>";
}
?>
4. Method Four:
Copy Code code as follows:
<?php
function list_dir ($dirpath) {
if ($ Dirpath[strlen ($dirpath) -1]!= "//") {$dirpath. = "//";}
static $result _array=array ();
if (Is_dir ($dirpath)) {
$dir =dir ($dirpath);
while ($file = $dir->read ()) {
if ($file = = "." | | $file = = "...") {continue;}
if (Is_dir ($dirpath. $file)) {
list_dir ($dirpath. $ File. " //");
}else{
array_push ($result _array, $dirpath. $file);
}
}
$dir->close ();
}
return $result _array;
}
$array =list_dir ("d:/www");
foreach ($array as $value) {
echo $value;
echo "<br>";
}
?>