haku Posted March 16, 2008 Share Posted March 16, 2008 I'm trying to figure out how to get the names of the folders in the current directory I am in. I want to use the names of these folders to build a list of links in current directory. I don't want to link to the files in the directory though, only the folders. So far I have figured out how to use scandir to get the names of all the files and folders in the directory, but I cant figure out how to isolate the folder names out of that. Anybody have any ideas? Quote Link to comment Share on other sites More sharing options...
Orio Posted March 16, 2008 Share Posted March 16, 2008 is_dir(): <?php $files = scandir("."); //Files + Folders foreach($files as $file) { if(is_dir($file)) //File is a directory { if($file != "." && $file != "..") //Current and parent directories echo $file." is a directory in this folder!"; } else echo $file." is not a directory in this folder!"; } ?> Orio. Quote Link to comment Share on other sites More sharing options...
Orio Posted March 16, 2008 Share Posted March 16, 2008 If you simply want to get a list of dirs in the current folder, use glob() instead: <?php $folders = glob("*", GLOB_ONLYDIR); ?> Orio. Quote Link to comment Share on other sites More sharing options...
haku Posted March 16, 2008 Author Share Posted March 16, 2008 Thank you sir. That is exactly what I was looking for! 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.