Julia: sort output of readdir

Created on 16 Nov 2017  路  5Comments  路  Source: JuliaLang/julia

on linux it is sorted, but not on windows. for cross-platform compatibility, might want to sort it on windows.

filesystem

Most helpful comment

I would propose adding a sort::Bool=true keyword argument to readdir so that people can opt out of the sorting operation if they really need to. Defaulting to true seems reasonable because directories do not tend to have that many entries in them and it's easy to write code assuming that this will always be sorted on one platform and have it break on another. With the opt-out keyword, at least you know that what you're getting won't necessarily be sorted.

All 5 comments

I would propose adding a sort::Bool=true keyword argument to readdir so that people can opt out of the sorting operation if they really need to. Defaulting to true seems reasonable because directories do not tend to have that many entries in them and it's easy to write code assuming that this will always be sorted on one platform and have it break on another. With the opt-out keyword, at least you know that what you're getting won't necessarily be sorted.

I will prepare a PR if no one minds.

"on linux it is sorted, but not on windows"

Yes, e.g. for ls, but besides asking for differents sorts, e.g. by time, I also see:

"-U do not sort; list entries in directory order"

In case that's the order actually stored in, and tiny bit faster, you could default to it, with sort=false?

"Huge bug uncovered ... because different operating systems sort files differently and the published scripts don鈥檛 handle it well." !!!

https://arstechnica.com/information-technology/2019/10/chemists-discover-cross-platform-python-scripts-not-so-cross-platform/

馃憤 That story pretty much demolished the somewhat weak (imo) arguments against doing this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tkoolen picture tkoolen  路  3Comments

omus picture omus  路  3Comments

manor picture manor  路  3Comments

TotalVerb picture TotalVerb  路  3Comments

Keno picture Keno  路  3Comments