4

アプリケーション用のフォルダー/サブフォルダー構造があります。

新しいモジュールを追加するときはいつでも、ファイルをコピーせずにフォルダー構造を正確にコピーする必要があります。

階層内のフォルダーとサブフォルダーをコピーし、ファイルはそのままにしておくにはどうすればよいですか?

4

2 に答える 2

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
    }
}
于 2012-07-05T12:30:45.117 に答える
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 $_ }
于 2012-07-05T13:41:19.383 に答える