php代码
/* * * * * * * * * * 列出文件夹下内容,返回数组 $dirArray['dir']:存文件夹;$dirArray['file']:存文件 * 刘先忠 2012-1-20 * * * * * * * * */ function getDirs($dir) { $dirArray [][] = NULL; if (false != ($handle = opendir ( $dir ))) { $i = 0; $j = 0; while ( false !== ($file = readdir ( $handle )) ) { if (is_dir ( $dir . $file )) { //判断是否文件夹 $dirArray ['dir'] [$i] = $file; $i ++; } else { $dirArray ['file'] [$j] = $file; $j ++; } } closedir ( $handle ); } return $dirArray; } $mydir = getDirs ( "./" ); print_r ( $mydir ['dir'] ); echo " "; print_r ( $mydir ['file'] );