In the recursive Scan folder tree problem, or Glob function of the performance of a bit better, very accurate said. The > Scandir function will be inexplicably scanned two times. File, that is, if there are two files for the minor evil.
>.. /b.php Tutorials and: /a.php, the results will appear on the scan report two times, it is very strange.
The code is as follows |
Copy Code |
Update at 2010.07.25-the following code is void $path = ' ... '; function Get_filetree_scandir ($path) { $tree = Array (); foreach (Scandir ($path) as $single) { if (Is_dir ('.. /'. $single)) { $tree = Array_merge ($tree, Get_filetree ($single)); } else{ $tree [] = '. /'. $single; } } return $tree; } Print_r (Get_filetree_scandir ($path)); Update at 2010.07.25-The following is the new code $path = './'; function Get_filetree_scandir ($path) { $result = Array (); $temp = Array (); if (!is_dir ($path) | |! Is_readable ($path)) return null; Detecting Catalog Validity $allfiles = Scandir ($path); Get all files and folders under directory foreach ($allfiles as $filename) {//Walk through files and folders in directory if (In_array ($filename, Array ('. ', '. '))) continue; Ignore. And.. $fullname = $path. ' /'. $filename; Get the full file path if (Is_dir ($fullname)) {//Is the directory Word continues recursion $result [$filename] = Get_filetree_scandir ($fullname); Recursive start } else { $temp [] = $filename; If it is a file, it is stored in an array } } foreach ($temp as $tmp) {//the contents of the temporary array are stored in an array of saved results $result [] = $tmp; This allows the folder to be in front of the file in the back } return $result; } Print_r (Get_filetree_scandir ($path)); |
http://www.bkjia.com/PHPjc/631703.html www.bkjia.com true http://www.bkjia.com/PHPjc/631703.html techarticle in the Recursive Scan folder tree problem, or Glob function of the performance of a bit better, very accurate said. The > Scandir function will be inexplicably scanned two times. /file, that is, if small ...