Jump to content

Noobie question - alphabetizing folder contents list


bostonjim

Recommended Posts

The following code is working for me, but the displayed results are not in alphabetical order.  I understand that I need to put them in an array and sort them, but don't have the foggiest about how to do that.

 

<?php  

function DirDisply($data) {  
      
     $TrackDir=opendir(".");  
      
     while ($file = readdir($TrackDir)) {  
          
      if ($file == "." || $file == "..") { }  
         else { 
             print "<tr><td><font face=\"Verdana, Arial, Helvetica, sans-serif\"><a href=$file target=_blank>$file</a></font> </td>"; 
                  
          } 
        
     }  
     closedir($TrackDir);  

return $data;  
}  

?> <b><font face="Verdana, Arial, Helvetica, sans-serif">Current Directory Contain 
Following files and Sub Directories...</font></b> 
<p> 
<?  
@ DirDisply($data);  
?>  

I tried using that and this is how the result appears:

 

Array
(
    [0] => .
    [1] => ..
)

 

So I must need to add it into the code I posted originally and not use it by itself, since it isn't grabbing any of the files or directories.  Any help would be greatly appreciated.

I have a slightly different question but it should be easy for the pros.  When I use this everything is showing up:

 

<?php
$tmp = glob('*');
echo '<pre>' . print_r($tmp,true) . '</pre>';
?>

 

But it appears like this on the screen:

 

Array
(
    [0] => archive.php
    [1] => comments.php
    [2] => directorycontents.php
    [3] => footer.php
    [4] => functions.php
    [5] => header.php
    [6] => images
    [7] => index.php
    [8] => page.php
)

 

How can I make it not show the part which says "Array" and the parenthesis.  And how can I make these into links?  I did my best to add the href tags into the echo line but I can't make it work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.