I was wondering, in .NET 4.0+, are the results of Directory.GetFiles
always guaranteed to be sorted by file name in ascending order?
Please note that I'm not asking how to sort the results, this I know how to do (https://stackoverflow.com/a/6294333/1203288), I just want to know if I have to sort them manually or not.
Asked
Active
Viewed 486 times
2
2 Answers
9
No. From MSDN:
The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.

Dave Zych
- 21,581
- 7
- 51
- 66
7
No. From the documentation for Directory.GetFiles
:
The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.

Reed Copsey
- 554,122
- 78
- 1,158
- 1,373
-
1sorry to not mark your answer as the correct one. you and DaveZych seemed to post at the exact same time with the exact same answer, so I marked his answer as correct since he has a much lower reputation than you. – bsara Oct 15 '12 at 21:10
-
1@Brandon You can mouseover the `answered Oct 15 at 20:55` on an answer for a more exact time - Reed was actually first, by 9 seconds! – Bridge Dec 21 '12 at 15:15
-
@Bridge Ha, good to know, I'll remember that for the future. They were both good answers and I did upvote them both. – bsara Dec 21 '12 at 17:00