2017-10-15 117 views
-2

我做了这样的事情之前,批处理文件如何使用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 

有一个这样做的优雅方式。 BONUS我也想指定多个扩展名(* .exe,* .txt,* .blob)并在一个命令中完成所有操作。

+2

*有一定是这样的一种优雅的方式* - 乞丐不能挑肥拣瘦。 'gci * .exe,*。txt | %{copy -L $ _ -D($ _。name +'。deploy')}' – TessellatingHeckler

+0

@WhiskerBiscuit:请求帮助之前,您尝试了哪些Powershell代码? – Manu

回答

0

使用PowerShell你要复制的文件和管道的结果枚举到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' } 
+0

啊,我不知道$ _ pipe的语法。这有帮助 – WhiskerBiscuit

相关问题