shage Posted January 29, 2008 Share Posted January 29, 2008 I currently can only list all files and folders in a dir, i would like a list of folders only in desc order, but am lost on how to just list only folders, thank you Quote Link to comment https://forums.phpfreaks.com/topic/88382-solved-list-only-folders/ Share on other sites More sharing options...
obsidian Posted January 29, 2008 Share Posted January 29, 2008 Check out the is_dir() function. Something like this should let you get directories into an array, and then you could sort them however you like: <?php $dir = 'path/to/dir/'; $folders = array(); // ...open your folder connection here and loop over contents while (false !== ($file = readdir($handle))) { if (is_dir($dir . $file)) { // It's a directory, so add it to the array: $folders[] = $file; } } // ...finish whatever else you need and close your handle ?> Quote Link to comment https://forums.phpfreaks.com/topic/88382-solved-list-only-folders/#findComment-452323 Share on other sites More sharing options...
adam291086 Posted January 29, 2008 Share Posted January 29, 2008 if your making an FTP client this tutorial is good http://www.devarticles.com/c/a/PHP/Building-An-FTP-Client-With-PHP/ Quote Link to comment https://forums.phpfreaks.com/topic/88382-solved-list-only-folders/#findComment-452324 Share on other sites More sharing options...
shage Posted January 29, 2008 Author Share Posted January 29, 2008 Warning: readdir(): supplied argument is not a valid Directory resource on Line 16 this is just to print out all the sites i have, not a ftp or anything, just to let me see the products we promote as each product has its own folder Quote Link to comment https://forums.phpfreaks.com/topic/88382-solved-list-only-folders/#findComment-452327 Share on other sites More sharing options...
shage Posted January 29, 2008 Author Share Posted January 29, 2008 while (false !== ($file = readdir($handle))) that being line 16 Quote Link to comment https://forums.phpfreaks.com/topic/88382-solved-list-only-folders/#findComment-452340 Share on other sites More sharing options...
trq Posted January 29, 2008 Share Posted January 29, 2008 Where do you define $handle? Quote Link to comment https://forums.phpfreaks.com/topic/88382-solved-list-only-folders/#findComment-452344 Share on other sites More sharing options...
laffin Posted January 29, 2008 Share Posted January 29, 2008 u define the handle with opendir such as handle=opendir("path/to/list"); Quote Link to comment https://forums.phpfreaks.com/topic/88382-solved-list-only-folders/#findComment-452404 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.