-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: File.Readdirnames order is different than of "ls -l" #43435
Comments
Directory order means the same order that the operating system returns. This depends on the OS type, version, and importantly the filesystem used at the path that was read. To get a predictable order across systems, you need to perform sorting yourself, as done by ioutil.ReadDir. I think this is working as intended and documented. Please comment if I missed something. |
@dmitshur Thanks for the feedback. brb with the result. |
I'll close this as there's no bug here, and we use the Go issue tracker for bugs and proposals only. For questions and discussion about using Go, please see https://golang.org/wiki/Questions for a list of better places. Thanks. P.S. In your snippet, please note that you should handle the error from |
As promised, got back with the result. I was about to close this issue anyway... 😊 As a summary, I am happy with these figures:
P.S. You're right, thanks! The code was just for this sample purposes. |
Yep, the time difference is expected because Note that starting with Go 1.16, there will be a new API |
Yes, read about the upcoming API. Thanks. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, this is the latest release at the time of this writing.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Since I want to find a more performant alternative to
ioutil.ReadDir
(that takes around 1.2 seconds if there are over 100.000 files in the directory), thisos.File.Readdirnames
seems to be the perfect option.But the order of entries that are provided does not seem to be
consistentthe same as ofls -l
. Of course, some ordering can be done on the result, but the whole point was to quickly get the next couple of files from a directory, sorted either by name or creation time.The API documentation mentions that:
Now, what in directory order means is yet unclear to me.
The code used is extremely simple:
What did you expect to see?
I was expected to see the same output as of
ls
:What did you see instead?
But - a concrete output, related to the same content as previously listed - the result of running the code is:
Any advice, please?
Thank you!
The text was updated successfully, but these errors were encountered: