![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Oct 2005
Posts: 5
Rep Power: 0
![]() |
readdir
hi, this is my first post here, i spect to learn a lot.
This question is more operationg system specific than php but the problem starts in php. According to php.net in function readdir description: "The filenames are returned in the order in which they are stored by the filesystem". Many people developed some code to sort these returned names and i think they are ok. For specific problems on my code i cant use the solutions provied. So, i am thinking on changing the order filenames are "sorted" on my linux server. Any idea on how to view this order and edit it? Thanx a lot. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
Instead of changing file systems, in what ways does the readdir function fail in your existing code. For instance, I make links to images on my disk like so:
[PHP] while($imgName = readdir($imgDir)) { if (($imgName != ".") || ($imgName != "..")) print("<A HREF=\"$imgName\">$imgName</A><BR>\n"); } [/PHP] If there is a particular order that you want, perhaps you can read them into a data structure and rearrange / sort them as needed?
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2005
Posts: 5
Rep Power: 0
![]() |
Hi Infinite recursion, thanx for the answer.
Unfortanly i dont understand your post correctly, my english is not the best and neither my code knowldge. Here is a bit of my code: $dirname = "/var/www/some/"; $dh = opendir($dirname); while($file = readdir($dh)) { if($file == '.' || $file == '..') { continue; } else { $oTemplate->newBlock('available'); $oTemplate->assign('template', $file); $oTemplate->assign('fintable', "</table><table align='center'>"); $dirname2 = "/var/www/some/".$file; $dh2 = opendir($dirname2); while($file2 = readdir($dh2)) { if($file2 == '.' || $file2 == '..') { continue; } else { $oTemplate->newBlock('name'); $name = $oDvd->idtoname($file2); $oTemplate->assign('dvd', $name); directories inside "some" are 1, 2, 3, 4. Output in template is: 3, 2, 4, 1 I want: 1, 2, 3, 4 Maybe this can clear u something. Thanx again. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
Yeah, makes sense to me... just a reverse of the file listing... no big deal.
As you read the directory contents put the files into an array, then reverse the array as you process the files... For example: My file list: Parent Directory - a 17-Feb-2006 13:15 0 b 17-Feb-2006 13:15 0 c 17-Feb-2006 13:15 0 d 17-Feb-2006 13:15 0 e 17-Feb-2006 13:15 0 f 17-Feb-2006 13:15 0 rlist.php 17-Feb-2006 13:38 414 The script to do what I mention above: [PHP] <?php $fileArray[] = ""; echo "<h3>Original Listing:</h3>"; $imgDir = opendir("."); while($imgName = readdir($imgDir)) { if (($imgName != ".") || ($imgName != "..")) { print("$imgName\n<br>"); array_push($fileArray,$imgName); } } echo "<p><hr><p><h3>Reverse Listing:</h3>"; $i = sizeof($fileArray); while ($i > 0) { print $fileArray[$i] . "<br>"; $i--; } ?> [/PHP] Demo the script here: http://www.jasonpowers.net/test/rlist.php
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|