Closed Thread Icon

Topic awaiting preservation: Order Alphabetically (sp?) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12441" title="Pages that link to Topic awaiting preservation: Order Alphabetically (sp?)" rel="nofollow" >Topic awaiting preservation: Order Alphabetically (sp?)\

 
Author Thread
Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-22-2002 10:16

Hello! we made this code here, to show all the files from a dir and its subdirs:

code:
<?php

function getDirList ($dirName) {
$counter = 0;
$d = dir($dirName);
while($entry = $d->read()) {

if ($entry != "." && $entry != "..") {
if (is_dir($dirName."/".$entry)) {
getDirList($dirName."/".$entry);

} else {
if (preg_match("/html\$/i", $entry))
{
echo "<a href=$dirName/$entry>$entry</a><br>";
}
}
}
}
$d->close();

}
getDirList("../thumbespos");
echo "</tr></table></TD> </TR></TABLE>";
?>



Is it possible to order it alphabetically?

I mean, the files! not the subdirs! (the subdirs are not listed, but it shows the files in order as it reads the subdirs)

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 09-22-2002 10:38

1. Collect all files in array (instead of showing them directly on screen)
2. Sort array (using sort() function)
3. Print array contents


Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-22-2002 12:17

Okies, I made it cool!
a could get the array (even when I hate arrays ) I could print it, but I couldn't sort it!
I checked the manual and the functios it's : SORT($array);

I was getting the array like this:
$a = array($entry);

And then, I printed the array:
for ($i = 0; $i < count($a); $i++) {

echo("$a[$i]<br>");
}

It prints cool.

But when I add the SORT($a); (right before the for loop) it gives me an error:
Warning: sort() expects parameter 1 to be array, null given in path/to/file.php on line xxx (teh SORT line)


Wakkos
follow the white rabbit

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 09-22-2002 15:54

what does the code on the 'SORT' line say?

is it an array or a string?

remember that it's telling you it's going to need an array... the kind that are defined with '@' as opposed to strings, which are defined with '$'...


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

[This message has been edited by Petskull (edited 09-22-2002).]

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 09-22-2002 22:25

I would have to wonder about how you are getting your array. I'm not saying that I know for sure there's anything wrong with it, but I've never done it that way.

Why don't you try something like this:

$a = array(); //Create empty array

Then in your while loop you can add $entry to your array like this:

array_push($a, $entry); //adds $entry to your array

Then you should be able to sort($a).



-Butcher-

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 09-23-2002 08:39

Wakkos, here's the complete working code...

<?php

// Written by mr.maX, http://www.max.co.yu/

/*

get_folder_List() function description

$folder - starting folder
$extensions - list of all file extensions
$entries - array where to store files (stored like this "filename

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-23-2002 09:11

Wow!!! that's a great code mr.maX! thanks a lot for your time!!
Pretty weet!
butcher, I tried yours, but even with that, it prints an unsorted array...

[This message has been edited by Wakkos (edited 09-23-2002).]

« BackwardsOnwards »

Show Forum Drop Down Menu