A php function that can traverse all files and subfolders in a folder.

WBOY
Release: 2016-07-29 09:12:24
Original
1045 people have browsed it

This function was written by someone else, I sorted it out. Added a lot of comments.

Function description:

This function execution process:

Detect directory->Open directory->Read directory->Remove special directory->Determine whether files still exist in the subdirectory->If so, repeat Call ->If not, put the file entry into the array->Close the folder->Return the folder entry.

/**
* Display the read directory in the form of an array
* @return array
* The opendir() function opens a directory handle, which can be used by closedir(), readdir() and rewinddir().
* The is_dir() function checks whether the specified file is a directory.
* The readdir() function returns the entry in the directory handle opened by opendir().
*/
function my_scandir($dir)
{
                                                                                                                                ( $dir))
                                                                                                                                     while(($file=readdir($handle))!==false )
{去 // Remove special directory
if ($ file! = "&& $ file! =" .. ") {
// Judging whether the subdirectory still exists in the subdirectory
iF (IS_DIR ($ dir. "/".$file))
                                                                                                                  ($dir."/".$file);
                                                           / /Get directory array
                                                                                ’ s ’ s } 1 - } } }                                                                                                                                                                                                                                                                                                               ;
                                                                                                                                                                                
The above introduces a php function that can traverse all files and subfolders in a folder. , including relevant 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!