Fearpig Posted September 13, 2006 Share Posted September 13, 2006 Hello, :)Could someone point me to a tutorial on how to list a folders contents in a descending order?I've got the code below that creates a list of links to all of the files in the specified folder and now I want to put these in a descending order by filename.[code]$path = "D:\\Intranet v3\TEST\StaffNotice"; $dir_handle = @opendir($path) or die("Unable to open $path"); while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." || $file == "index.php") continue; echo "<a href='$file'>$file</a><br>"; } closedir($dir_handle); [/code]Thank you! Link to comment https://forums.phpfreaks.com/topic/20603-solved-sort-files-listed-from-directory/ Share on other sites More sharing options...
Fearpig Posted September 13, 2006 Author Share Posted September 13, 2006 Ignore it again, I found out how!!Stick it in an array and use krsort($array_name)! Link to comment https://forums.phpfreaks.com/topic/20603-solved-sort-files-listed-from-directory/#findComment-90962 Share on other sites More sharing options...
Gruzin Posted September 13, 2006 Share Posted September 13, 2006 Offtopic: Fearpig, can you please tell me how did you change the topic title?Thank you. Link to comment https://forums.phpfreaks.com/topic/20603-solved-sort-files-listed-from-directory/#findComment-90964 Share on other sites More sharing options...
redarrow Posted September 13, 2006 Share Posted September 13, 2006 goto your first post on a page you psted then click modify and alter the topic title.good luck. Link to comment https://forums.phpfreaks.com/topic/20603-solved-sort-files-listed-from-directory/#findComment-90965 Share on other sites More sharing options...
HuggieBear Posted September 13, 2006 Share Posted September 13, 2006 Please can you post the solution...RegardsRich Link to comment https://forums.phpfreaks.com/topic/20603-solved-sort-files-listed-from-directory/#findComment-90966 Share on other sites More sharing options...
wildteen88 Posted September 13, 2006 Share Posted September 13, 2006 [quote author=Gruzin link=topic=107888.msg433334#msg433334 date=1158147727]Offtopic: Fearpig, can you please tell me how did you change the topic title?Thank you. [/quote]It was me that changed the topic title, if you are wondering how *solved* got added into the topic title. I used the inline thread title editor. Link to comment https://forums.phpfreaks.com/topic/20603-solved-sort-files-listed-from-directory/#findComment-90974 Share on other sites More sharing options...
Fearpig Posted September 13, 2006 Author Share Posted September 13, 2006 Thanks Wildteen.....Huggiebear, here you go.............[code]$thefiles = array(); //initialize arrayif ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php" && $file != "test.php" && !is_dir($file)) { //ignore some of the system files in that folder //use filesystem functions to get the filesize and other attributes RTFM $thefiles[] = array('filename' => $file); //used this way, it just adds the new item to the end of the array // it is creating an array of arrays } } closedir($handle);}//at this point the $thefiles array contains all the file info//access it using 2 indexes like this echo $thefiles[0]['filetype'];//use array functions to sort $thefiles array to your pleasure RTFM//use the foreach() to cycle through the $thefiles array and echo the files and other attributes outkrsort($thefiles);foreach ($thefiles as $singlefile) { $Doc = $singlefile['filename']; echo "<a class='Body2' href='$Doc'>$Doc</a><br>"; }[/code] Link to comment https://forums.phpfreaks.com/topic/20603-solved-sort-files-listed-from-directory/#findComment-90976 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.