Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 17th, 2006, 11:35 AM   #1
anarki
Newbie
 
Join Date: Oct 2005
Posts: 5
Rep Power: 0 anarki is on a distinguished road
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.
anarki is offline   Reply With Quote
Old Feb 17th, 2006, 12:58 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Feb 17th, 2006, 1:07 PM   #3
anarki
Newbie
 
Join Date: Oct 2005
Posts: 5
Rep Power: 0 anarki is on a distinguished road
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.
anarki is offline   Reply With Quote
Old Feb 17th, 2006, 1:46 PM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC