The following small make up will bring you a PHP recursive traversal of files in a specified folder implementation method. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the file and folder chapter on the subway this morning. I just recently learned about the linux file system and thought that accessing file attributes is similar to Shell commands, so I want to practice it at night.
It seems that the php folder function does not provide the ability to traverse all files in the folder (including files in subdirectories), so you just want to implement one by yourself.
During writing, I found that some folder-related functions were not as intended. For example, dirname () obtains the path of the folder where the file is located based on the provided complete file path, but if you input a folder, it takes its parent folder. This must be understood. The same is true for basename (). the name of the folder is obtained by passing in the folder path. Neither of the two functions Returns '/' at the end of the result '/'
'; $ Deep ++; // depth + 1 recursion_readdir ($ path, $ Deep);} else if (basename ($ path )! = '.' AND basename ($ path )! = '..') {// Not a folder. print the file name echo forChar ('-', $ Deep). basename ($ path ).'
';}} Closedir ($ resDir );}
The above PHP recursive traversal of the file implementation method in the specified folder is all the content shared by Xiaobian. I hope to give you a reference and support for PHP Chinese.
For more articles about PHP recursive file traversal in a specified folder, refer to PHP Chinese network!