2012-07-05 37 views

回答

5

這是一個有點「哈克」爲PowerShell不處理這個非常好......接受的觀點說,使用XCOPY或的Robocopy,但如果你真的需要使用PowerShell,這似乎工作確定:

$src = 'c:\temp\test\' 
$dest = 'c:\temp\test2\' 

$dirs = Get-ChildItem $src -recurse | where {$_.PSIsContainer} 

foreach ($dir in $dirs) 
{ 
    $target = ($dir.Fullname -replace [regex]::Escape($src), $dest) 

    if (!(test-path $target)) 
    { 
     New-Item -itemtype "Directory" $target -force 
    } 
} 
3
$source = "<yoursourcepath>" 
$destination = "<yourdestinationpath>" 

Get-ChildItem -Path $source -Recurse -Force | 
    Where-Object { $_.psIsContainer } | 
    ForEach-Object { $_.FullName -replace [regex]::Escape($source), $destination } | 
    ForEach-Object { $null = New-Item -ItemType Container -Path $_ } 
相關問題