0

1つのフォルダーから約40フォルダーの特定のサブフォルダーにすべての(8ファイル)ファイルをコピーするスクリプトを作成しようとしました...

このように * から始めて、そのフォルダーからすべてのファイルをコピーします。しかし、もちろん、このようにはうまくいきませんでした:

* の付いたフォルダー名はランダムに変化し、8 つのファイルすべてを取得する EmailTemplates というサブフォルダーがあります。

Copy-Item d:\www\example\*   -destination d:\example\2\*\EmailTemplates

簡単な解決策はありますか?前もって感謝します!

4

1 に答える 1

1

宛先フォルダを選択するためにこのようなものは機能しますか?

$destination = Get-ChildItem "D:\example\2" -Recurse | ? {
    $_.PSIsContainer -and $_.Name -eq "EmailTemplates"
  }

それ以外の場合は、おそらく次のように宛先を決定する必要があります。

$destination = Get-ChildItem "D:\example\2" |
  ? { $_.PSIsContainer } |
  % { Join-Path $_.FullName "EmailTemplates" } |
  ? { Test-Path -LiteralPath $_ } | Get-Item

次に、次のようにファイルをコピーします。

Get-ChildItem "d:\www\example" | ? { -not $_.PSIsContainer } | % {
  Copy-Item $_.FullName $destination.FullName
}
于 2013-07-10T14:16:48.230 に答える