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

我只是一个虾纸丫 提交于 2019-12-23 08:47:42

问题


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.


回答1:


First folders in alphanumeric order (first numbers as [char]).
Then files in alphanumeric order (first numbers as [char]).



回答2:


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.




回答3:


Sorting by default doesn't work for me. I get:

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        2015-10-12     10:51            tools
d----        2015-10-12     10:58            cfg
d----        2015-10-12     10:51            res
d----        2015-10-12     10:50            brand
d----        2015-10-12     10:51            lib

I don't recall changing sort order. I'm on Windows 7 SP1. If I need sorted result I have to do ls | sort.



来源:https://stackoverflow.com/questions/15807802/what-is-the-default-order-of-result-set-from-get-childitem-command-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!