2017-05-11 26 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コマンドレットは、宛先内部ランダム引用符を持っており、終了引用符をミス。あなたが最後のスラッシュを心配する必要はありませんので、私はJoin-Pathコマンドレットを使用して、あなたをお勧めします:

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

注:単一ファイルをコピーしているので、私も-recurseパラメータを削除しました。

関連する問題