4
我們正在爲我們的應用程序提供文件夾/子文件夾結構。如何使用Powershell創建文件夾結構框架?
無論何時添加新模塊,我們都必須完全複製文件夾結構,而無需複製文件。
如何複製層次結構中的文件夾和子文件夾,但保留文件單獨?
我們正在爲我們的應用程序提供文件夾/子文件夾結構。如何使用Powershell創建文件夾結構框架?
無論何時添加新模塊,我們都必須完全複製文件夾結構,而無需複製文件。
如何複製層次結構中的文件夾和子文件夾,但保留文件單獨?
這是一個有點「哈克」爲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
}
}
$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 $_ }