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? Link to comment https://forums.phpfreaks.com/topic/96401-get-folder-names-in-current-directory/ 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. Link to comment https://forums.phpfreaks.com/topic/96401-get-folder-names-in-current-directory/#findComment-493365 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. Link to comment https://forums.phpfreaks.com/topic/96401-get-folder-names-in-current-directory/#findComment-493366 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! Link to comment https://forums.phpfreaks.com/topic/96401-get-folder-names-in-current-directory/#findComment-493367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.