Jump to content

Recommended Posts

hello i have this script that outputs all directory's and files the problem i am having is i can sort alphabetically

 

say i have a file named

 

a1

a2

a10

a3

 

the way it is sorting them is like this

a1

a10

a2

a3

 

but i want to sort them like this

a1

a2

a3

a10

 

 

here is my script please help its driving me nutty

 

 

 

<?php

function Treemenu($path)

{

    //using the opendir function

    $dir_handle = @opendir($path) or die("Unable to open $path");

   

    //Leave only the lastest folder name

    $dirname = end(explode("/", $path));

$TEST = array();   

$i=0;

    //display the target folder.

    echo ("<li>$dirname\n");

    echo "<ul>\n";

    while (false !== ($file = readdir($dir_handle)))

    {

        if($file!="." && $file!="..")

        {

            if (is_dir($path."/".$file))

            {

                //Display a list of sub folders.

                Treemenu($path."/".$file);

            }

            else

            {

                //Display a list of files.

                $TEST[$i] = "<li><a href=\"{$path}/{$file}\">" .str_replace('.htm','',$file). "</a></li>";

$i++;

            }

        }

    }

sort($TEST);

echo implode('', $TEST);

    echo "</ul>\n";

    echo "</li>\n";

   

    //closing the directory

    closedir($dir_handle);

}

Treemenu('games')

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.