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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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/ |
|
|||
|
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/ |