开发者

how to iterate over files with powershell?

开发者 https://www.devze.com 2023-01-14 17:24 出处:网络
I want to iterate over files in a folder using po开发者_如何学Gowershell script;Get-ChildItem | ForEach-Object { <# do what you need to do #> }

I want to iterate over files in a folder using po开发者_如何学Gowershell script;


Get-ChildItem | ForEach-Object { <# do what you need to do #> }

or shorter:

gci | % { <# ... #> }

or if you want an explicit looping construct:

foreach ($file in Get-ChildItem) {
    # ...
}

Note however, that foreach will only run once all output from Get-ChildItem is collected. In my opinion most Powershell code should use the pipeline as much as possible.

0

精彩评论

暂无评论...
验证码 换一张
取 消