반응형
하위 폴더로 폴더를 복사하는 방법은 무엇입니까?
이 스크립트는 PowerShell에서 완벽하게 작동합니다.특정 유형의 모든 파일을 복사합니다.하지만 폴더 및 하위 폴더와 함께 파일을 복사하고 싶습니다.
$dest = "C:\example"
$files = Get-ChildItem -Path "C:\example" -Filter "*.msg" -Recurse
foreach ($file in $files) {
$file_path = Join-Path -Path $dest -ChildPath $file.Name
$i = 1
while (Test-Path -Path $file_path) {
$i++
$file_path = Join-Path -Path $dest -ChildPath
"$($file.BaseName)_$($i)$($file.Extension)"
}
Copy-Item -Path $file.FullName -Destination $file_path
}
PowerTip:PowerShell을 사용하여 항목 복사 및 폴더 구조 유지
질문:Windows PowerShell 3.0을 사용하여 드라이브에서 네트워크 공유로 폴더 구조를 복사하고 원래 구조를 유지하는 방법은 무엇입니까?
답변: 사용Copy-Item
cmdlet을 지정하고 다음을 지정합니다.–Container
전환된 매개 변수:
$sourceRoot = "C:\temp"
$destinationRoot = "C:\n"
Copy-Item -Path $sourceRoot -Filter "*.txt" -Recurse -Destination $destinationRoot -Container
언급URL : https://stackoverflow.com/questions/43867840/how-to-copy-folder-with-subfolders
반응형
'programing' 카테고리의 다른 글
express는 'body-parser deprecommended extended'로 오류를 발생시킵니다. (0) | 2023.08.26 |
---|---|
Set-Content가 내 파일 끝에 새 줄(줄 바꿈, CRLF)을 추가합니다. (0) | 2023.08.26 |
Python을 사용하여 미니돔으로 요소 값 가져오기 (0) | 2023.08.26 |
스크립트 태그에서 온로드 이벤트를 실행하려고 합니다. (0) | 2023.08.26 |
Get-ChildItem은 어떻게 결과가 없음(파일 0개)에 대해 테스트할 수 있습니까? (0) | 2023.08.26 |