Sorting number reversed problem...

Discussion in 'Programming' started by Peuplarchie, Jan 21, 2009.

  1. #1
    Good day top you all,
    I'm working on a script that read a folder a list directory.
    The files in that folder are named by number, like 0 to 200.

    here how it would look like :

    003
    002
    001
    010
    ...

    How can I make my list in complete reverse order like :

    010
    ...
    003
    002
    001


    here is my code :

    
    function listFilesInDir($start_dir)
    
            {
            
            /*
            returns an array of files in $start_dir (not recursive)
            */
                    
            $files = array();
            $dir = opendir($start_dir);
    $count =0;
            while(($myfile = readdir($dir)) !== false)
                    {
                    if($myfile != '.' && $myfile != '..' && !is_file($myfile) && $myfile != 'resource.frk' && !eregi('^Icon',$myfile) )
                            {
    						$count = $count +1;	
                            $files[] = $myfile;
                            }
                    }
            closedir($dir);
    		rsort($files);
            return $files;
    		
    
            }
    
    PHP:
    Thanks !
     
    Peuplarchie, Jan 21, 2009 IP
  2. Peuplarchie

    Peuplarchie Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Solved !
    
    natsort($files);
    $files = array_reverse($files);  
    
    PHP:
     
    Peuplarchie, Jan 21, 2009 IP