Arranging Contents of file by date added

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
maboroshi
Forum Commoner
Posts: 25
Joined: Thu Nov 13, 2003 10:10 am

Arranging Contents of file by date added

Post by maboroshi »

Hi I searched for this for a while on google but could not find anything

I have a script that access a directory I would like the contents of my directory to be arranged by date added descending

any help is alway's appreciated

Thank You
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

i'm pretty sure that php cant access the win32 created file info, so unless you were to name your files like blah_1_16_04.blah then you can just explode() the file name
ilovetoast
Forum Contributor
Posts: 142
Joined: Thu Jan 15, 2004 7:34 pm

Post by ilovetoast »

To get file info you can use:

fileatime - for time file was last accessed, on Win32 it will return last modified time

filemtime - for time last modified

filectime - detects last time inode was changed, useless on Win32

and of course the mother of all file info commands:

stat (see http://www.php.net/manual/en/function.stat.php)

peace
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

as i thought you cant decern the date the file was created.
ilovetoast
Forum Contributor
Posts: 142
Joined: Thu Jan 15, 2004 7:34 pm

Post by ilovetoast »

Actually you could hack together a way of doing it on a Unix system.

Basically you use symlinks.

Make a symlink for each file, and never use them. Check the symlinks last modified time using lstat(). You can update and change the files all you want, without chaning the last mod (and therefore creation date) of the symlink.

Of course you'd need to filter your directory listing to get only the symlinks......
Post Reply