Powershell Copy-Item上升几个目录

Powershell Copy-Item going up few directories

我试图在Powershell中提供Copy-Item cmdlet的路径,该路径会上升几个目录,但出现错误

"ERROR - failed with error:"A positional parameter cannot be found
that accepts argument '......\\'."

我要执行的命令是

1
Copy-Item $Source +"..\\..\\.." + ($environment) +"\\*.config" $destination

任何人都可以指导我如何在提供Copy-Item

路径的同时上几个目录


您需要在第一个参数(源)上加上括号:

1
Copy-Item ($Source +"..\\..\\.." + ($environment) +"\\*.config") $destination

在组合路径时,请考虑使用Join-Path cmdlet。您还可以编写如下内容:

1
2
$sourceDir = Join-Path (Get-Item $Source).Parent.Parent.Parent $environment
Get-ChildItem -Path $sourceDir -Filter '*.config' | Copy-Item -Destination $destination


我只需要在整个路径上用双引号引起来,而不是串联在一起。

1
Copy-Item"$Source\\..\\..\\..\\$environment\\*.config" $destination