cooldude832 Posted October 12, 2007 Share Posted October 12, 2007 I want to return all the subfolders in a given folder any idea? I thought glob can only do files. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 12, 2007 Author Share Posted October 12, 2007 should mention i can use scandir as i'm on 4 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 12, 2007 Author Share Posted October 12, 2007 I did $dir = ROOT."discus"; $dh = opendir($dir) or die($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; } but I can't get the thing to open it Quote Link to comment Share on other sites More sharing options...
corbin Posted October 12, 2007 Share Posted October 12, 2007 Ahhh... Here's something I wrote like 6 months ago.... Looking at it now, it looks kind of... bleh, but hopefully it'll give you the right idea ;p. It's a recursive function, but it could be done without a recursive function. function ListFiles($folder) { $out = array(); $han = opendir($folder); $f = (!empty($folder)) ? $folder . '/' : ''; while($it = readdir($han)) { if($it == '.' || $it == '..') continue; if(!is_dir($f.$it)) { $out[] = (strlen($folder) > 0) ? $folder . '/' . $it : $it; continue; } $path = (strlen($folder) > 0) ? $folder . '/' . $it : $it; $out = array_merge($out, ListFiles($path)); } return $out; } print_r(ListFiles('some/folder')); Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 12, 2007 Author Share Posted October 12, 2007 I solved it using <?php $dir = "discus/messages"; $dh = opendir($dir) or die($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; } sort($files); for($i=2; $i<=62; $i++){ $folders[] = $files[$i]; } ?> the 2 to 62 range is the folders I am reading, only because I cheated and saw what the folders where Quote Link to comment Share on other sites More sharing options...
corbin Posted October 12, 2007 Share Posted October 12, 2007 You could just do count($files) to get the 62, or you could do a foreach loop if you didn't want it statically set ;p. Quote Link to comment 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.