Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default order of result set from Get-ChildItem command in powershell?

What is the default order of result set from Get-ChildItem command in powershell? Is there a order at all or is it just random and would give the results in a different order every time.

like image 454
Hemant Avatar asked Apr 04 '13 09:04

Hemant


1 Answers

There is no guaranteed default sort order. The documentation doesn't state one.

The implementation in FileSystemProvider ends up calling DirectoryInfo.GetFiles. The documentation for that states

The order of the returned file names is not guaranteed; use the Sort method if a specific sort order is required.

The underlying API calls are Find­First­File and FindNextFile. Raymond Chen explains here that in practice the file system driver may observe some ordering rules but this should not be relied upon.

like image 125
Martin Smith Avatar answered Oct 20 '22 20:10

Martin Smith