Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Changing directory read order

11:55 am on Nov 26, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 12, 2003
votes: 0

I have made a small file management utility, but I still have a small design problem. When I read through the directory I get the folders and files in a mixed order since it is read by the time and date they were added, when I would like to get the folders first, and then the files.

Does anyone know if this can be done. I think I can probably get it done, by having one routine just reading all the folders in the directory, and then one routine reading all the files, but I was wondering if there was an easier way, or a smarter way :)

Thanks for any help thrown my way.

3:51 pm on Nov 26, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 7, 2003
votes: 0

How do you want to sort them? Are you wanting to put directories ahead of files, and then alphabetically within those two groups?

It depends on which platform you're using and how directories are designated. On *nix, there is a "d" in the attributes column that can be used to seperate directories from files. On Windows, these are designated by "<DIR>".

Seperate your values into two arrays, directories and files. Then you can create a function and use usort() to sort them.

3:56 pm on Nov 26, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 26, 2003
votes: 0

Have you looked at the user comments on the directory functions pages on php.net? I haven't looked but this sounds like the kind of thing somebody may have posted there.