note 60498 added to function.scandir

From: Date: Mon, 09 Jan 2006 06:02:04 +0000
Subject: note 60498 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-101435@lists.php.net to get a copy of this message
I made a small dir listing based on file modification date, could find alot on this myself so I hope this helps someone. <? $dirView="./blah"; $dirFiles=scandir($dirView); $cwdName=array(); $cwdMod=array(); $whatWeNeed=array(); // Parallel arrays (ignore the ".", ".." and inturn hidden files foreach ($dirFiles as $data) { if (!preg_match('/^\./', $data)) { $cwdName[]=$data; $cwdMod[]=filemtime($dirView."/".$data); } } // Merge and sort $mergeArray=array_combine($cwdMod, $cwdName); krsort($mergeArray, SORT_NUMERIC); // Build new array foreach ($mergeArray as $key => $value) { $whatWeNeed[]=$value; } // Some maintainence unset($dirFiles, $cwdName, $cwdMod, $mergeArray); # Then can grab latest changed file/folder with whatWeNeed[0] and so on.. ?> Tested with error_reporting(E_ALL); and PHP5.1 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60498 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60498&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60498&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60498&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60498&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60498&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60498&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60498&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60498&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101435) next »