Page 1 of 1

filemtime() of a Directory???

Posted: Fri May 28, 2004 5:39 pm
by Chris Corbyn
Hi,

Is there a function which gets the last modifed time of a directory or the created time of it?

I know you can do it with files using filemtime() - I've used it many times - but it doesn't seem to work for directories i.e.

Code: Select all

$modified = filemtime('C:\\Directory\\Subdirectory');
I've basically got a list of directories (in an array) which I want PHP to sort by the last modified/created time.

Any ideas?

PS: I've tried filectime too but I get the same (apparently) random ordering of directories. I know what the newest one is and it never even appears in the top 10.

Thanks in advance :-)

Posted: Fri May 28, 2004 5:49 pm
by kettle_drum
Ummm you tried stat() ?

Posted: Fri May 28, 2004 6:05 pm
by Chris Corbyn
I'm looking at it now but if I'm using it correctly (documentation isn't too good for it) then I think it doesn't work neither.

I'm doing this:

Code: Select all

$dir = 'C:\\My Albums\''.$subdir;
$stats_array = stat($dir);

$mod_time = array_slice($stats_array, 9, 1);
I'll test it by making a folder right now and converting what stat brings back as it's unix timestamp to one I can read and see if it's correct. Don't think it works though.

Posted: Fri May 28, 2004 6:10 pm
by Chris Corbyn
Tried this to test it...

Code: Select all

<?php

$stat_array = stat('C:\\testfolder');

$modtime = array_slice($stat_array, 9, 1);

echo $modtime;

?>
... and the output is
Array

I must be using the function wrong.

Posted: Fri May 28, 2004 6:12 pm
by Chris Corbyn
I'm such a tool.... What was I thinking??? I should have echoed $modtime[0] not just the little slice of the array.

Posted: Fri May 28, 2004 6:16 pm
by Chris Corbyn
Nope, still the same. The order I get my directories listed in never changes but it's wrong...

Posted: Fri May 28, 2004 6:22 pm
by Chris Corbyn
Ok, Now I've started adding new folders to my parent directory it seems to read the newest ones as just that. But all the others seem to be just random. Oh, now I've got an idea what it might be.... I've changed the files within the folders prior to doing this and maybe it's reading that as a direactory modification....

Probably explains it.

Thanks for the tip! :-)