glob 可用參數:
GLOB_MARK | 若檔案為資料夾,在回傳檔案路徑的最後面加上斜線"\" |
GLOB_NOSORT | 保持檔案路徑在原資料夾的出現順序(不重新排序) |
GLOB_NOCHECK | 若找不到匹配的檔案路徑,回傳匹配的條件字串 |
GLOB_NOESCAPE | 不要將反斜線視為跳脫字元 |
GLOB_BRACE | 將 {a,b,c} 視為搜尋 'a', 'b', 或 'c' |
GLOB_ONLYDIR | 只列出資料夾路徑 |
GLOB_ERR | 發生讀取錯誤時停止動作(像是無法讀取的資料夾),預設是「忽略錯誤」 |
應用範例:
<?php
//以遞迴的方式,取得資料夾下所有資料夾的路徑
function listdirs($dirf, $mark=1) {
static $alldirs = array();
if ($mark==1)
{
$alldirs = null;
}
$dirs = glob($dirf . '/*', GLOB_ONLYDIR);
if (count($dirs) > 0) {
foreach ($dirs as $d) $alldirs[] = $d;
}
foreach ($dirs as $dirf) listdirs($dirf, 0);
return $alldirs;
}
$dirf="./";
var_dump(listdirs($dirf, $mark=1));
?>
執行結果:
array (size=4)
0 => string './/ADS_ATop_Do' (length=14)
1 => string './/ClassPHP' (length=11)
2 => string './/js' (length=5)
3 => string './/ADS_ATop_Do/JAScript' (length=23)
期待您的留言

Comments