PHP code PHP code that traverses all directories and files in the specified directory

WBOY
Release: 2016-07-29 08:47:20
Original
1005 people have browsed it

Copy code The code is as follows:


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 read Specify the directory to the array

Copy the code The code is as follows:


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.'
';
}

The above introduces the PHP code to traverse all directories and files in the specified directory, including PHP code content. I hope it will be helpful to friends who are interested in PHP tutorials.

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template