jacko310592 Posted November 18, 2009 Share Posted November 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/182031-solved-get-all-files-within-a-directory-and-subdirectories/ Share on other sites More sharing options...
premiso Posted November 18, 2009 Share Posted November 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182031-solved-get-all-files-within-a-directory-and-subdirectories/#findComment-960136 Share on other sites More sharing options...
jacko310592 Posted November 18, 2009 Author Share Posted November 18, 2009 thanks premiso, i'll look into that Quote Link to comment https://forums.phpfreaks.com/topic/182031-solved-get-all-files-within-a-directory-and-subdirectories/#findComment-960141 Share on other sites More sharing options...
jacko310592 Posted November 18, 2009 Author Share Posted November 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/182031-solved-get-all-files-within-a-directory-and-subdirectories/#findComment-960160 Share on other sites More sharing options...
premiso Posted November 18, 2009 Share Posted November 18, 2009 Well done. Please mark topic solved (bottom left hand corner), thanks for posting the solution as well! Quote Link to comment https://forums.phpfreaks.com/topic/182031-solved-get-all-files-within-a-directory-and-subdirectories/#findComment-960164 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.