I read a chapter about files and folders on the subway this morning. I just recently understood the Linux file system and felt that accessing file attributes is very similar to Shell commands, so I wanted to practice it in the evening.
I found that PHP's folder function did not seem to provide traversal of all files in a folder (including files in subdirectories), so I wanted to implement one myself.
While writing, I found that some functions for operating folders were not what I thought. For example, dirname() gets the path to the folder where the file is based on the complete file path provided, but if you pass in a folder, it gets its parent folder. This needs to be understood. The same is true for basename(). If you pass in the folder path, you will get the name of the folder. The results returned by these two functions do not end with '/'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
The above implementation method of PHP recursively traversing files in a specified folder is all the content shared by the editor. I hope it can give you a reference, and I also hope that you will pay more attention to the PHP Chinese website.
For more related articles on how to implement PHP recursive traversal of files in a specified folder, please pay attention to the PHP Chinese website!