Home > Backend Development > PHP Tutorial > Use PHP to recursively loop through each directory_PHP tutorial

Use PHP to recursively loop through each directory_PHP tutorial

WBOY
Release: 2016-07-21 15:34:44
Original
755 people have browsed it

The principle of the function is very simple, mainly using recursive calls.

Copy code The code is as follows:

function file_list($path){
if ($handle = opendir($ path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($path."/".$file)) {
echo $path.": ".$file."
";//Remove this line to display all non-directories File
file_list($path."/".$file);
} else {
echo $path.": ".$file."
";
}
}
}
}
}

This function can also continue to make some improvements, adding some folder or file icons, etc., so that it can be made more powerful This is a function. Friends who are interested can expand it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322337.htmlTechArticleThe principle of the function is very simple, mainly using recursive calls. Copy the code The code is as follows: function file_list($path){ if ($handle = opendir($path)) { while (false !== ($file = re...
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