0

ソースフォルダーからファイルのサブセットをコピーしてターゲットフォルダーに配置するPowerShellスクリプトを作成しようとしています。「アイテムのコピー」と「アイテムの削除」で半日遊んでいますが、希望する結果や一貫した結果が得られません。

たとえば、次のコマンドレットを複数回実行すると、ファイルは別の場所に配置されますか?!?!:

copy-item -Path $sourcePath -Destination $destinationPath -Include *.dll -Container -Force -Recurse

私は考えられるオプションとコマンドのすべての組み合わせを試してきましたが、適切な解決策を見つけることができません。私は非定型のことは何もしていないと確信しているので、誰かが私の痛みを和らげ、使用する適切な構文を提供してくれることを望んでいます。

ソースフォルダには、さまざまな拡張子を持つ多数のファイルが含まれます。たとえば、次のすべてが可能です。

  • .dll
  • .dll.config
  • 。EXE
  • .exe.config
  • .lastcodeanalysisissucceeded
  • .pdb
  • .Test.dll
  • .vshost.exe
  • .xml
  • 等々

スクリプトは、.test.dllおよび.vshost.exeファイルを除いて、.exe、.dll、および.exe.configファイルのみをコピーする必要があります。ターゲットフォルダがまだ存在しない場合は、それらを作成するためのスクリプトも必要です。

私を動かす助けがあればありがたいです。

4

2 に答える 2

1

try:

$source = "C:\a\*"
$dest =  "C:\b"

dir $source -include *.exe,*.dll,*.exe.config -exclude *.test.dll,*.vshost.exe  -Recurse | 
% {

 $sp = $_.fullName.replace($sourcePath.replace('\*',''), $destPath)

 if (!(Test-Path -path (split-path $sp)))
    {
     New-Item (split-path $sp) -Type Directory
    } 

    copy-item $_.fullname  $sp -force
  }
于 2012-11-17T22:27:09.260 に答える
0

ファイルが1つのディレクトリにある限り、以下は正常に機能するはずです。必要以上に冗長かもしれませんが、出発点としては適切です。

$sourcePath = "c:\sourcePath"
$destPath = "c:\destPath"

$items = Get-ChildItem $sourcePath | Where-Object {($_.FullName -like "*.exe") -or ($_.FullName -like "*.exe.config") -or ($_.FullName -like "*.dll")}

$items | % {
    Copy-Item $_.Fullname ($_.FullName.Replace($sourcePath,$destPath))
}
于 2012-11-15T19:23:14.490 に答える