Re: Reading Directory in reverse

From: Date: Thu, 23 Jan 2003 12:51:25 +0000
Subject: Re: Reading Directory in reverse
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-132810@lists.php.net to get a copy of this message
It does not read it in reverse alphabetical order, but in the order it is listed on the filesystem, which happens to be in reverse alphabetical order. If you need it ordered, use $files=array(); if (!($dp = opendir($default_dir))) die("cannot open $default_dir"); while($file = readdir($dp))
       if($file != '.' && $file != '..') $files[]=$file;
closedir($dp); sort($files); foreach($files as $file) { echo"<a href='opendir.php?opendir=$file'>$file</a><BR>"; } Bob Irwin wrote:
Hi Guys, Does anyone happen to know why the below code reads the directory in reverse alphabetical order? Not a major problem - easy enough to whack it in an array and sort it, but annoying nonetheless. $default_dir = "../screenshots"; if (!($dp = opendir($default_dir))) die("cannot open $default_dir"); while($file = readdir($dp))
       if($file != '.' && $file != '..') echo"<a
href='opendir.php?opendir=$file'>$file</a><BR>"; closedir($dp); Best Regards Bob Irwin Server Admin & Web Programmer Planet Netcom


« previous php.general (#132810) next »