2013年1月15日星期二

【转】PHP遍历文件及文件夹

  <?php
$dir = 'F:\\game';


function read_dir_all($dir) {
$ret = array('dirs'=>array(), 'files'=>array());
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if($file != '.' && $file !== '..') {
$cur_path = $dir . DIRECTORY_SEPARATOR . $file;
if(is_dir($cur_path)) {
$ret['dirs'][$cur_path] = read_dir_all($cur_path);
} else {
$ret['files'][] = $cur_path;
}
}
}
closedir($handle);
}
return $ret;
}

$p = read_dir_all($dir);
echo '<pre>';
var_dump($p);
echo '</pre>';
?>
  摘自:http://zhidao.baidu.com/question/112668432.html

没有评论: