Directory statistics

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
jwb
Forum Newbie
Posts: 1
Joined: Sun Nov 30, 2003 10:29 am

Directory statistics

Post by jwb »

I hate "asking" for code, but I need some help. I'm considerably rusty on my PHP skills and would like to do this with a decent method.

Basically, I'd like to get statistics for subdirectores in a tree of directories (horribly explained.) Including the total size, the filecount, and possibly the oldest/newest file. For example...

/home/*/.maildir/Spam/
where * is each subdir in /home/
(To generate spam statistics)

I have an idea of the basic function of doing this, but can't put it all together. If anyone could lend assistance, it'd be mucho appreciated. Thanks.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

I would say a combination of the dir directory class in a recursive function couple with some *nix commands like wc (if I'm not mistaken) and ls. Check out functions like stat(), filemtime() and fileatime(). scandir() would be nice, but it's P5 CVS so you may not want that.

1) I'm assuming you're using a *nix.
2) You can find info on dir at http://us2.php.net/manual/en/class.dir.php
3) If you don't know what a recursive function is, google or alltheweb.com can show you the light.

Cheerrs,
BDKR
Post Reply