簡體   English   中英

如何使用Powershell創建文件夾結構框架?

[英]How to create folder structure skeleton using Powershell?

我們的應用程序有文件夾/子文件夾結構。

每當我們添加新模塊時,我們都必須完全復制文件夾結構而不復制文件。

如何復制層次結構中的文件夾和子文件夾,但只保留文件?

這有點'hacky',因為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 $_ }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM