Heck, why doesn't this built-in function write like this?
PHP Code
$path = ' e:/zl/data -1/database/3005 Audi a6l new C6 original data '; 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));
Replace {*.pdf,*.doc,*.ppt} with * To display all files, directories and files ....
------Solution--------------------
Write like this
PHP code
function 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;}
------Solution--------------------
You can use the same method as you did, but with the wrong target
if (Glob ($path. */*. {pdf,doc,ppt} ", Glob_brace) {
should be
if (GLOB ($single.") {pdf,doc,ppt} ", Glob_brace) {
To determine whether the suffix of the $single is compliant
I # # code:
//Get all eligible file names
foreach (GLOB ($path.") /*. {pdf,doc,ppt} ", Glob_brace) as $single) {
if (Is_file ($single)) $tree [] = $single;
}
//Traverse all subdirectories
foreach (Glob ($path. " /* ", Glob_onlydir) as $single) {
$tree = Array_merge ($tree, Get_filetree ($single));
}