I'm want to create a script that searches through a directory (basedir) and all of it's sub-directories. To find the 5 last modified files.
The only problem is, I don't know how to start. I already got the list of all files in the basedir, only I don't know how to get along with the rest of the script
Could someone give me a clue or a tip?
You can use recursion. Make your directory listing function so that it takes a directory as an argument: list_dir($directory); Then modify the function so that it calls itself every time it finds a directory.
But, if you are on a un*x machine:
$output = system("ls -lR $directory");
and parse the output. Faster and less work :-)
Hmm, just off the top of my head, for NT on might try:
$output = system("dir $directory /b /s");
NB the result will have one line per file, and will always begin at the root including the drive letter, even if $directory is relative.