方法一
$dir = "e:/myphp/research/mailapi";
$dirs = array();
function scan_dir($dir) {
global $dirs;
if (!is_dir($dir)) return false;
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file[0] == '.') continue;
$fullpath = "$dir/$file";
$dirs[] = $fullpath;
if (is_dir($fullpath)) scan_dir($fullpath);
}
closedir($dh);
}
return $dirs;
}
//scan_dir($dir);
//print_r($dirs);
方法二
function scan_dir2($dir) {
global $dirs;
if (!is_dir($dir)) return false;
if ($dh = dir($dir)) {
while (($file = $dh -> read()) !== false) {
if ($file[0] == '.') continue;
$fullpath = "$dir/$file";
$dirs[] = $fullpath;
if (is_dir($fullpath)) scan_dir2($fullpath);
}
$dh->close();
}
return $dirs;
}
scan_dir2($dir);
print_r($dirs);
部分结果:
Array
(
[0] => e:/myphp/research/mailapi/163
[1] => e:/myphp/research/mailapi/163/163.php
[2] => e:/myphp/research/mailapi/baseclass
[3] => e:/myphp/research/mailapi/baseclass/baseclass.php
[4] => e:/myphp/research/mailapi/gmail
[5] => e:/myphp/research/mailapi/gmail/9063271b89460d5d4395cdfae8994089
[6] => e:/myphp/research/mailapi/gmail/gmail-lite
[7] => e:/myphp/research/mailapi/gmail/gmail-lite/chat.gif
[8] => e:/myphp/research/mailapi/gmail/gmail-lite/clip.gif
[9] => e:/myphp/research/mailapi/gmail/gmail-lite/compose.php
[10] => e:/myphp/research/mailapi/gmail/gmail-lite/config.php
[11] => e:/myphp/research/mailapi/gmail/gmail-lite/diagnose.php
[12] => e:/myphp/research/mailapi/gmail/gmail-lite/dl.php
[13] => e:/myphp/research/mailapi/gmail/gmail-lite/favicon.ico
[14] => e:/myphp/research/mailapi/gmail/gmail-lite/glite.css
...
...
[15] => e:/myphp/research/mailapi/gmail/gmail-lite/index.php