[英]How to, using CMD/Powershell, find all files in a directory (including subdirectories), and then display files that have certain extensions
[英]How can I copy all files in a directory matching certain extensions with PowerShell?
我以前用批處理文件做過這樣的事情
copy "%APPPATH%\*.exe" "%APPPATH%\*.exe.deploy"
所以我想將所有.exe
文件復制到 `.exe.deploy'
因此,如果我在目錄中有以下內容:
a.exe
b.exe
c.foo
d.bar
我想結束:
a.exe
b.exe
c.foo
d.exe
a.exe.deploy
b.exe.deploy
d.exe.deploy
必須有一種優雅的方式來做到這一點。 獎勵我還想指定多個擴展名(*.exe、*.txt、*.blob)並在一個命令中完成所有操作。
使用 PowerShell,您可以枚舉要復制的文件並將結果通過管道Copy-Item
到Copy-Item
cmdlet:
Get-ChildItem $env:APPPATH -Filter *.exe |
Copy-Item -Destination { $_.FullName + '.deploy' }
請注意, -Filter
僅支持單個字符串。 如果你想傳遞多個擴展,你需要使用-Include
(但只能與-Recurse
結合使用):
Get-ChildItem $env:APPPATH -Include *.exe,*.foo -Recurse |
Copy-Item -Destination { $_.FullName + '.deploy' }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.