note 12909 deleted from function.readdir by philip

From: Date: Fri, 08 Nov 2002 01:53:24 +0000
Subject: note 12909 deleted from function.readdir by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-39113@lists.php.net to get a copy of this message
<?php # If you want to list the files # in a directory sorted by # date then you can use # the code below (probably could # be more efficient - but it works!) # $dir_name="/path/to/directory"; $dir = opendir($dir_name); $basename = basename($dir_name); $fileArr = array(); while ($file_name = readdir($dir)) { if (($file_name !=".") && ($file_name != "..")) { #Get file modification date... # $fName = "$dir_name/$file_name"; $fTime = filemtime($fName); $fileArr[$file_name] = $fTime; } } # Use arsort to get most recent first # and asort to get oldest first arsort($fileArr); $numberOfFiles = sizeOf($fileArr); for($t=0;$t<$numberOfFiles;$t++) { $thisFile = each($fileArr); $thisName = $thisFile[0]; $thisTime = $thisFile[1]; $thisTime = date("d M y", $thisTime); echo"<b>$thisName</b> $thisTime <br>"; } closedir ($dir); ?>

« previous php.notes (#39113) next »