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.
精彩评论