Folder count in a folder, and get the names of the folders

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Folder count in a folder, and get the names of the folders

Post by kaisellgren »

Ciao! I've searched through PHP documentation but I couldn't find any function that will return the foldercount and the foldernames in a specified folder. I need to get the count of all folders in a folder. Then I need to know the names of those folders, ordered by desceding name order. Is there any function?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

glob() can return just directories, and can sort them, however they may not be a human logical sort. You can use natsort() for that. As for getting the number of folders, use count() on the return from glob().
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Well here's something I'm going to need for my image gallery :)
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Post by kaisellgren »

Oh, I made it good, but there's one bug. PHP will return my folder as "../skins/ironlook", it should only return the name of the folder, ironlook. The .php is in different folder than the folders I'm counting. Hmm, any ways to remove the ../skins/ off ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it tries to return full pathing information. Using basename() on each entry should get you the result you are after.
Post Reply