我想在目录文件中找到example-file-5.0.0.0.jar
并复制重命名到另一个目录。我写了这个脚本:
Get-ChildItem -Path $directoryFrom | Where-Object { $_.Name -match "example-file-\d\.\d\.\d\.\d\.jar$" } | Copy-Item -Destination $directory\"example-file.jar -Recurse -Force
问题是,我example-file-5.0.0.0-debug.jar
在同一个目录中有另一个文件名,它被复制而不是example-file-5.0.0.0.jar
文件。我怎样才能解决这个问题?
你错过了别的东西。你-match
是对的:
"example-file-5.0.0.0-debug.jar" -match "example-file-\d\.\d\.\d\.\d\.jar$"
# Output: False
"example-file-5.0.0.0.jar" -match "example-file-\d\.\d\.\d\.\d\.jar$"
# Output: True
但是,您的Copy-Item
cmdlet 在目标内有一个随机引号并且错过了结束引号。我建议您使用Join-Path
cmdlet,这样您就不必担心尾部斜杠:
Copy-Item -Destination (Join-Path $directory "example-file.jar") -Force
注意:我还删除了该-recurse
参数,因为您正在复制单个文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句