2013-07-10 23 views
0

複製8個文件,我試圖讓一個腳本,複製所有(8個文件)從一個文件夾中的文件到各地〜40個文件夾的子文件夾的具體...從一個文件夾到其他40子

我開始喜歡這個用*將所有文件複製出該文件夾。 但當然它並沒有像這樣工作:

*隨機更改的文件夾名稱,並有一個名爲EmailTemplates的子文件夾應該得到我所有的8個文件。

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

有沒有簡單的解決方案? 在此先感謝!

回答

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 
} 
+0

謝謝你,幫我很多,我做了它有點不同,但你幫我做到了 – RayofCommand

相關問題