Powershell 将版本控制的文件复制到其他目录

Powershell 将版本控制的文件复制到其他目录,powershell,Powershell,我想在目录文件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 问题是,我在同一目录中有另一个名为ex

我想在目录文件
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
是正确的:

但是,您的
Copy Item
cmdlet在目标中有一个随机引号,并且错过了结束引号。我建议您使用
Join-Path
cmdlet,这样您就不必担心后面的斜杠:

Copy-Item -Destination (Join-Path $directory "example-file.jar") -Force
注意:我还删除了
-recurse
参数,因为您要复制单个文件

Copy-Item -Destination (Join-Path $directory "example-file.jar") -Force