std.file.dirEntries unsorted

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Wed Dec 11 12:10:47 PST 2013


On Wednesday, 11 December 2013 at 18:34:54 UTC, Timothee Cour 
wrote:
> yes, I agree sorting should be explicit as there's no natural 
> order.
> However sorting after calling dirEntries is not great as 
> typically one
> wants to sort within a given directory level and it's too late 
> to sort once
> all the directory levels are flattened.
> so how about having an extra argument that takes a lambda (eg
> binaryFun!"a<b") in dirEntries, or, having an additional 
> function in
> std.file that takes such lambda.

Why is it too late, the file name includes the full path so 
sorting will still sort sibling directories separately.

     foreach(de; dirEntries(".", 
SpaneMode.depth).array.sort!((a,b)=>a.name<b.name)) ...

This seems reasonable for your need, but I didn't test to check 
the behavior. dirEntries isn't random access so we can't sort it 
directly. I don't think placing it in dirEntries saves much and 
it would hide the required array allocation.


More information about the Digitalmars-d-learn mailing list