www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Sort order of dirEntries

reply Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
Hello all,

I've just been playing with dirEntries and by the looks of it, it returns these 
entries in arbitrary order.

Is there a way to get it to sort the entries in alphabetical order, other than 
the obvious one of storing them in an array and sorting that?  (This is 
untenable because I'm talking about a lot of files...:-)

Thanks and best wishes,

     -- Joe
Oct 24 2012
parent "Regan Heath" <regan netmail.co.nz> writes:
On Thu, 25 Oct 2012 01:15:06 +0100, Joseph Rushton Wakeling  
<joseph.wakeling webdrake.net> wrote:

 Hello all,

 I've just been playing with dirEntries and by the looks of it, it  
 returns these entries in arbitrary order.

On windows, assuming it was using FindFirstFile or similar you would get alphabetical order on some platforms/file systems and FAT table order on others. I imagine linux and associated platforms have similar behaviour.
 Is there a way to get it to sort the entries in alphabetical order,  
 other than the obvious one of storing them in an array and sorting  
 that?  (This is untenable because I'm talking about a lot of files...:-)

To get a sorted list someone has to load all the entries and sort them. I doubt the file system is going to do it, so either the library routine would have to, or you're going to have to. As most file systems and libraries should take the most efficient approach first and foremost it's likely you're going to have to do it yourself. :) R -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Oct 26 2012