I got a folder structure like so
css
main.css
home
layout.css
menu.css
...
account
user.css
menu.css
user
user.css
level
time.css
...
...
You can see a lot of files and folders nested in each other. I want loop through folder css, read every files and folders in it. If a file, run function do(), if a folder run function make() and continue to loop through that folder to check for files and folders inside. Repeat the process until there are no more folder and file left to loop through.
I can easily loop through the files and folders if I know how exactly how many there are. The problem is I don’t know how many folders and files there are. So there need to be a special technique to archive what I want ?
This would be perfect for the RecursiveDirectorIterator class that comes with PHP. It’ll loop through each file and folder recursively. Each item that you iterate through will be a subclass of
SplFileInfowhich contains many function you can use (e.g. getBasename(), getCTime(), getExtension(), and many more).