アプリケーション用のフォルダー/サブフォルダー構造があります。
新しいモジュールを追加するときはいつでも、ファイルをコピーせずにフォルダー構造を正確にコピーする必要があります。
階層内のフォルダーとサブフォルダーをコピーし、ファイルはそのままにしておくにはどうすればよいですか?
アプリケーション用のフォルダー/サブフォルダー構造があります。
新しいモジュールを追加するときはいつでも、ファイルをコピーせずにフォルダー構造を正確にコピーする必要があります。
階層内のフォルダーとサブフォルダーをコピーし、ファイルはそのままにしておくにはどうすればよいですか?
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 $_ }