std.file.dirEntries unsorted

Jonathan M Davis jmdavisProg at gmx.com
Wed Dec 11 13:21:35 PST 2013


On Wednesday, December 11, 2013 10:34:29 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.

You can use SpanMode.shallow if you just want to look at a directory at a time 
- or as Jesse points out, you could sort on the entire path. Regardless, 
dirEntries can't sort for you, because in order to do that it would have to 
allocate a container of some kind (be it an array or something else) in order 
to hold all of the entries and then sort them, whereas dirEntries is lazy and 
doesn't hold anything other than the info on where it currently is in the list 
of directories. The actual file list is held by the OS. So, you might as well 
just implement what you want on top of dirEntries. What you're asking for is 
already essentially a wrapper around dirEntries - one that would have to 
allocate on the heap no less - so it really makes more sense for it to be done 
outside of dirEntries.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list