Seperating Files from Folders in a directory listing?

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
Rob_Beard
Forum Newbie
Posts: 23
Joined: Sat Oct 12, 2002 11:58 am

Seperating Files from Folders in a directory listing?

Post by Rob_Beard »

Hey all.

I'd like to know how to seperate files from folders in a directory list? anyone know how to do that.

I've scoured the PHP manual until I couldnt tell a tree from a dog, but with no luck.
seg
Forum Commoner
Posts: 38
Joined: Thu Oct 31, 2002 12:08 pm
Location: Northern, VA
Contact:

Post by seg »

I don't have a direct answer for you, but these are my first thoughts on the issue.

On a server running Windows, something like exec(attrib, $list) then you can do a str function to locate directories and files since a blank attrib command echos the attributes of all directories and files in the current directory.

On a *nix machine, maybe 'cmod', or 'ls', output it to a variable then search the variable for the right chmod flags.

Like i said, its not a solid answer, but I hope its heading in the right direction.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

seg
Forum Commoner
Posts: 38
Joined: Thu Oct 31, 2002 12:08 pm
Location: Northern, VA
Contact:

Post by seg »

sad2891
Forum Newbie
Posts: 9
Joined: Sat Nov 02, 2002 8:38 pm
Location: Orlando, Florida

search for "."

Post by sad2891 »

all i did when i needed to do that was search for a period in the filename, if it was a folder it didnt have one and if it was a file it did (to seperate the file extension). And if you wanted to, you could use regex to make it more precise.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: search for "."

Post by twigletmac »

sad2891 wrote:all i did when i needed to do that was search for a period in the filename, if it was a folder it didnt have one and if it was a file it did (to seperate the file extension). And if you wanted to, you could use regex to make it more precise.
Erm, is_file() and is_dir() are the really simple way of doing this as volka pointed out.

Mac
Post Reply