Home > php教程 > php手册 > PHP遍历文件夹与子目录

PHP遍历文件夹与子目录

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:14:24
Original
996 people have browsed it

我们可以使用的函数有 Scandir,它的作用是列出指定路径中的文件和目录,就像 Dir 一样, 以及更强力的 Glob() 函数,作用是以数组的形式返回与指定模式相匹配的文件名或目录。 一. 遍历单层文件夹: function get_dir_glob(){ $tree = array(); foreach(glo

我们可以使用的函数有 Scandir,它的作用是列出指定路径中的文件和目录,就像 Dir 一样,

以及更强力的 Glob() 函数,作用是以数组的形式返回与指定模式相匹配的文件名或目录。 

一. 遍历单层文件夹: 

function get_dir_glob(){ 

$tree = array(); 

foreach(glob(‘./*’) as $single){ 

echo $single.”
\r\n”; 

get_dir_glob(); 

二. 递归遍历文件树: 

Glob 函数扫描非常准确,并且会自动排好顺序:

$path = ‘..’; 

function get_filetree($path){ 

$tree = array(); 

foreach(glob($path.’/*’) as $single){ 

if(is_dir($single)){ 

$tree = array_merge($tree,get_filetree($single)); 

else{ 

$tree[] = $single; 

return $tree; 

print_r(get_filetree($path));

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template