LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Arranging Files In Alphabetical order (https://www.linuxquestions.org/questions/linux-general-1/arranging-files-in-alphabetical-order-509497/)

swatward 12-11-2006 04:17 PM

Arranging Files In Alphabetical order
 
This seems like it'd be really simple, but how do i arrange files by alphabetical order from command line.

If i have
aaa.mp3
fff.mp3
bbb.mp3
that should be
aaa
bbb
fff.

How do i Do this?
I'm just blanking out here.

zetabill 12-11-2006 04:20 PM

Normally ls gives it's output in alphabetical order by default. Are you using something else?

swatward 12-11-2006 04:24 PM

er sorry, yeah bad questions. I have an upload script that also lists the files a a certain order, but it's doing it in some random order.

Heres the code for the sorting part

PHP Code:

$handle=opendir($upload_dir);
$filelist "";
while (
$file readdir($handle)) {
   if(!
is_dir($file) && !is_link($file)) {
      
$filelist .= "
<table border=1><tr><td bgcolor='white' width='100%'><a href='
$upload_dir$file'>".$file."</a></td>";

      
$filelist .="";
   } 


matthewg42 12-11-2006 05:29 PM

Put the results of readdir in an array, and then call sort on it. You can then iterate over the array and test for directories and links (and discard them).

You can see an example here. It must be true - google told me.

swatward 12-11-2006 08:14 PM

aight cool, thanks.


All times are GMT -5. The time now is 03:46 PM.