遍历指定目录下的所有目录和文件的php代码_PHP

WBOY
Release: 2016-06-01 12:13:58
Original
843 people have browsed it
复制代码代码如下:
function listFiles($path){
$result = array();
foreach(glob($path.'\\'."*") as $item){
$result[strtolower($item)] = $item;
if(is_dir($item)){
$result += listFiles($item);
}
}
return $result;
}
$path = 'E:\\web\\dianle';
foreach(listFiles($path) as $item){
echo $item.'
';
}

2: scandir 读取指定目录到数组
复制代码代码如下:
function listFiles($path){
$result = array();
foreach( scandir($path) as $item ){
if($item != '.' && $item != '..' ){
$item = $path.'\\'.$item;
$result[strtolower($item)] = $item;
if(is_dir($item)){
$result += listFiles($item);
}
}
}
return $result;
}
$path = 'E:\\web\\dianle';
foreach(listFiles($path) as $item){
echo $item.'
';
}
Related labels:
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!