Jump to content

[SOLVED] Get all Files within a Directory and Subdirectories


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.