2017-05-11 1 views
1

디렉토리 파일 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 파일의 복사 점이다. 이 문제를 어떻게 해결할 수 있습니까?

답변

1

다른 것이 누락되었습니다. 귀하의 -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 매개 변수를 제거하면 하나의 파일을 복사하기 때문에.

관련 문제