473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.
Jul 17 '05 #1
3 9329
date( "d/m/y", $file )

Frizzle.

Jul 17 '05 #2
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/

Jul 17 '05 #3
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/
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
11
by: Dennis Marks | last post by:
There seems to be a major program with the automatic display of the last modified date. Using the javascript "document.lastModified" sometimes returns the correct date and sometimes 1 Jan 1970...
1
by: | last post by:
Hi- I was curious if anyone has had good luck using one of the commercial .NET FTP client libraries to perform massive LIST commands. I have tried various free libraries with no/little success,...
1
by: RML | last post by:
hey guys, i am looking at this piece of code that lists numbers of files in a directory. i want to convert it so it lists the files in th directory that end with .doc. i cant seem to get it to...
11
by: Madison Kelly | last post by:
Hi all, I am new to the list and I didn't want to seem rude at all so I wanted to ask if this was okay first. I have a program I have written in perl which uses a postgresSQL database as the...
1
by: mich dobelman | last post by:
How can i just get the last modification date from the header list. I though I can $request->headers to get the modification date, but without success. <?php include( "Snoopy.class.php" );...
3
by: rn5a | last post by:
I am not very sure whether I should have continued with my earlier thread or started a new thread whose subject matter was somewhat similar to the subject matter in this thread. Anyway after much...
1
by: BobJr | last post by:
Two tables "tblEmployee" and "tblEmployeeHistory". Each table has identical fields. Each field on the form "frmEmployee" detects a change (BeforeUpdate) and checks a corresponding box (hidden...
1
by: poornimayv | last post by:
hi, I have one file which contains information of some data. I need to get a full description of all files modified from a particular date (Date which is read from a text file). And then...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.