list directories by date modified?

This is a discussion on list directories by date modified? within the PHP Language forums, part of the PHP Programming Forums category; I have a script that reads all directory names within a specific location (only containing folders), then lists all jpeg ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2005
Eclectic
 
Posts: n/a
Default list directories by date modified?

I have a script that reads all directory names within a specific
location (only containing folders), then lists all jpeg files in those
directories. Here is my script:

function getDir($dir,$foldername){
$d2 = opendir($dir);
while (false !== ($file = readdir($d2))) {
$ext=substr($file,(strlen($file)-3),strlen($file));
if($ext=="jpg" || $ext=="JPG"){
// list $file under heading $foldername
}
}
}

$d1 = opendir('ONLINE/');
while (false !== ($folder= readdir($d1))) {
if($folder!="" && $folder!="." && $folder!=".."){
getDir('ONLINE/'.$folder."/",$folder);
}
}

At the moment, the dirs are read alphabetically, but I would like to
list them by order of date modified.

Can PHP retrieve date information from dirs? If so, how does one do
it?

Cheers,

Eclectic.
Reply With Quote
  #2 (permalink)  
Old 04-17-2005
frizzle
 
Posts: n/a
Default Re: list directories by date modified?

date( "d/m/y", $file )

Frizzle.

Reply With Quote
  #3 (permalink)  
Old 04-17-2005
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: list directories by date modified?

Eclectic wrote:
<snip>
> At the moment, the dirs are read alphabetically, but I would like to
> list them by order of date modified.
>
> Can PHP retrieve date information from dirs? If so, how does one do
> it?


http://in2.php.net/filemtime

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Reply With Quote
  #4 (permalink)  
Old 04-17-2005
Ewoud Dronkert
 
Posts: n/a
Default Re: list directories by date modified?

On 16 Apr 2005 19:20:49 -0700, Eclectic wrote:
> $ext=substr($file,(strlen($file)-3),strlen($file));


Easier: $ext = substr( $file, -3 );

> while (false !== ($folder= readdir($d1))) {
>
> At the moment, the dirs are read alphabetically


No, they are read in 'system order' which happens to be alphabetically
(maybe because they were created in that order? see php.net/readdir). If
you want to list the dirs in some particular order, you have to read
them all first, then sort the array, then process the results.

$folders = array();
$index = array();

$basedir = './';
$dh = opendir( $basedir );

clearstatcache();
while ( FALSE !== ($entry = readdir( $dh )) )
if ( $entry != '.' && $entry != '..' )
{
$path = $basedir.$entry;
if ( is_dir( $path ) )
{
$folders[] = $path;
$index[] = filemtime( $path );
}
}

asort( $index );
foreach ( $index as $i => $t )
echo date( 'd-m-Y H:i:s', $t ).' '.$folders[$i]."\n";


--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:20 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0