Jump to content

sorting list in file directory


networkthis

Recommended Posts

I am having a difficult time alphabetically sorting the following code that I have written.  I have tried to make this into an array and then sort it but everytime I try I come up empty...any help would be greatly appreciated.  I can get a basic file list to sort alphabetically but for some reason this is killing me. Thanks...

 

<?php
function showFolder($path){

# Open the Directory Path
if ($handle = opendir($path))
   	{

while (false !== ($file = readdir($handle)))
    {
  			#*****************************************#
		# Remove Files that are named . , .. and  #
		# any others we wish to add that we don't # 
		# want displayed in the main directory.   #
		#*****************************************#

		if ($file != "." && $file != "..")
            {
			# Fname will be used to simply copy the Actual Name of the File!!!
			$fName = $file;

			# Create the path for the file
			$file = $path.'/'.$file;


			#*****************************************#
			# Simply checks to see if the $file is    #
			# actually a DIRECTORY.  If it is display #
			# the following.                          #
			#*****************************************#
			if (is_dir($file)) {
		    print "<tr><td colspan='2'><img src='../style/dir2.gif' width='16' height='16' 
			alt='dir'/> <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>";
                }
	}
	}

       closedir($handle);
   	}	

}
?> 

Link to comment
https://forums.phpfreaks.com/topic/121504-sorting-list-in-file-directory/
Share on other sites

I am just familiar with using them as an array then using a foreach loop and sorting....... I wrote the above slightly different and just had all my code finished with outputing on the pages as I wished minus the alphabeticall part.......... 

 

I have never even heard of the glob() function but I guess I will be checking it out on php.net now to see what it does and how it works.

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.