blackmamba5069 asked:
I hope that makes sense…
I hope that makes sense…
Basically, I want to scan through one particular directory, which contains several subdirectories which all contain several text files, and list each one of these text files.
How can I do this? Just looking for a quick and simple answer seeing as I’m still new to PHP!


2 Comments to 'How to list all files within all subdirectories of a directory using PHP?'
February 11, 2010
See the user comments for scandir().
February 14, 2010
Here you go. I’ve written this recursive function for you. Edit the first line with the path to your starting folder. Make sure you end it with a slash. If you’re hosting on windows this may not be perfect because of the direction of slashes (/ vs \) in the directory path. The result of the getFiles function is an array containing all the files in every folder down from where you started. The keys of the array are the folder names, values file names.
Dave Arnold
Training Specialist
Leave a comment