Jump to content

[SOLVED] Get all Files within a Directory and Subdirectories


jacko310592

Recommended Posts

Hey guys,

 

is there a way to scan all subdirectories within a main directory for JPG files?

 

i know how to use 'Glob' to grab JPG files from a single/current directory, just cant find a wayto make it grab all JPG files from all the subdirectories.

 

is this even possible?

 

thanks

You will have to use loops, mainly recursive loops.

 

scandir may also help you in your trek, but it is possible. Look at the manual for glob and scandir, I am sure there is user-contributed code that already does this for you. No need to re-invent the wheel.

i think i solved it, just thought id share incase anyone else is also trying to do the same thing...

 

<?php
$it = new RecursiveDirectoryIterator("gallery");
foreach(new RecursiveIteratorIterator($it) as $file) {
echo $file . "\n";
}
?>

 

which gets all the files it can find within the main directory,

then you can just use...

 

if (stristr($file, "indexThumb.jpg")===FALSE)

 

to make it exclude any files/subdirectories you dont want it to pick up

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.