您好,欢迎访问一九零五行业门户网

活见鬼,为什么这个内置函数这样写不行

见鬼,为什么这个内置函数这样写不行?
php code$path = 'e:/zl/资料-1/资料库/3005 奥迪a6l新型c6原厂资料';function get_filetree($path){ $tree = array(); foreach(glob($path./{*.pdf,*.doc,*.ppt}, glob_brace) as $single){ if(is_dir($single)){ $tree = array_merge($tree,get_filetree($single)); } else{ $tree[] = $single; } } return $tree;}print_r(get_filetree($path));
把{*.pdf,*.doc,*.ppt} 换成 * 就可以显示所有文件了,目录有些文件....
------解决方案--------------------
这样写php codefunction get_filetree($path){ $tree = array(); foreach(glob($path./*.{pdf,doc,ppt}, glob_brace) as $single) { if(is_file($single)) $tree[] = $single; } foreach(glob($path./*, glob_onlydir ) as $single) { $tree = array_merge($tree,get_filetree($single)); } return $tree;}
------解决方案--------------------
你#6的写法也是可以的,但用错了目标
if(glob($path.*/*.{pdf,doc,ppt}, glob_brace)){
应为
if(glob($single.{pdf,doc,ppt}, glob_brace)){
目的是判断 $single 的后缀是否符合要求
我#4的代码:
//取得所有符合条件的文件名
foreach(glob($path./*.{pdf,doc,ppt}, glob_brace) as $single) {
if(is_file($single)) $tree[] = $single;
}
//遍历所有子目录
foreach(glob($path./*, glob_onlydir ) as $single) {
$tree = array_merge($tree,get_filetree($single));
}

其它类似信息

推荐信息