Simple directory iterator that is recursive and shows all files and directories/sub-directories.
I don’t see any built in function to exclude certain file types, for instance in the following example I do not want to output any image related files such as .jpg, .png, etc. I know there are several methods of doing this , looking for advice on which would be best.
$scan_it = new RecursiveDirectoryIterator("/example_dir");
foreach(new RecursiveIteratorIterator($scan_it) as $file) {
echo $file;
}
Update:
Ok, so I’m an idiot. PHP has a builtin for this:
pathinfo()Try this:
Original Answer:
Why not just run
substr()on the filename and see if it matches the extension of the file type you want to exclude:You could make it easier by using regular expressions:
You could even use an array to keep track of your file types: