Powershell:对目录中的所有文件执行操作(foreach)

Joh*_*ley 3 powershell

在 bash 中,相当于

for x in `ls *.zip` do ; unzip $x ; done
Run Code Online (Sandbox Code Playgroud)

如何在 Windows Powershell 中执行此操作。

更新正如 Johannes Rössel 指出的那样,这是一个不好的例子(解压缩 *.zip),但我所追求的是它的“foreachness”。

Joh*_*ley 6

ls *.zip | foreach-object { unzip $_ }
Run Code Online (Sandbox Code Playgroud)

  • 规范的 powershell 使用 `gci` 或 `Get-ChildItem`。 (3认同)
  • 不幸的例子:`unzip *.zip` 很容易工作。 (2认同)