Get-ChildItem파일 이름 필터를 재귀 적으로 포함하여 파일과 디렉토리를 나열 할 수 있습니다. Copy-Item파일을 복사 할 수 있습니다.
파일 선택과 관련하여 많은 부분이 겹치는 경우가 종종 Copy-Item있으며 , 필요한 세부 사항에 따라 자체적으로 충분합니다 (예 : 폴더 구조를 유지 하시겠습니까?).
모든 복사하려면 *.foo및 *.barStartFolder에서 DestFolder에를 :
Copy-Item -path "StartFolder" -include "*.foo","*.bar" -Destination "DestFolder"
폴더 구조를 유지해야하는 경우 대상 폴더 이름을 빌드해야하기 때문에 상황이 더 어려워집니다.
$sourcePath = 'C:\StartFolder'
$destPath = 'C:\DestFolder'
Get-ChildItem $sourcePath -Recurse -Include '*.foo', '*.bar' | Foreach-Object `
{
$destDir = Split-Path ($_.FullName -Replace [regex]::Escape($sourcePath), $destPath)
if (!(Test-Path $destDir))
{
New-Item -ItemType directory $destDir | Out-Null
}
Copy-Item $_ -Destination $destDir
}
그러나 robocopy더 쉬울 것입니다 :
robocopy StartFolder DestFolder *.foo *.bar /s
결국 선택하는 방법은 필요한 세부 사항에 달려 있습니다.
(위에서는 별명을 피하고 (예 : Copy-Item대신 copy) 매개 변수 이름이 위치에 있더라도 명시 적으로 사용합니다.)