한 폴더에서 다른 폴더로 새 파일만 복사하고 5분 전에 추가된 파일만 복사하는 방법은 무엇입니까?

한 폴더에서 다른 폴더로 새 파일만 복사하고 5분 전에 추가된 파일만 복사하는 방법은 무엇입니까?

한 드라이브에서 다른 드라이브로 파일을 복사하고 싶지만 대상 파일보다 최신인 소스 파일만 복사하고 싶습니다. 하지만 지난 5분 동안 변경된 소스 파일만 복사하고 싶습니다.

확장자가 .bat인 파일 하나를 만들고 다음 명령을 사용했습니다.

xcopy "C:\Users\Pictures\Newfolder"  "C:\Users\Pictures\Newfolder2\" /d:03/29/2019

하지만 이 명령은 날짜에 대한 명령입니다.

답변1

이 PowerShell 스크립트는 다음과 같습니다.

(Get-ChildItem 'C:\Users\Pictures\Newfolder' |
    Where {!($_.PSIsContainer) -and
           ($_.LastWriteTime -gt [datetime]::now.AddMinutes(-5)) -and 
           (!(Test-Path (Join-Path 'C:\Users\Pictures\Newfolder2' $_.Name)))}).FullName"

배치 파일로 래핑됩니다.

:: Q:\Test\2019\03\29\SU_1419009.cmd
@Echo off
Set "Src=C:\Users\Pictures\Newfolder"  
Set "Dst=C:\Users\Pictures\Newfolder2"

For /f "usebackq delims=" %%A in (`
    powershell -NoP -C "(Get-ChildItem '%Src%'|Where {!($_.PSIsContainer) -and ($_.LastWriteTime -gt [datetime]::now.AddMinutes(-5)) -and (!(Test-Path (Join-Path '%Dst%' $_.Name)))}).FullName"
`) Do (
echo Copy "%%A" "%Dst%\"
     Copy "%%A" "%Dst%\"
)

그대로 이것은 지난 5분 동안 생성/변경된 파일만 복사합니다. 잘못 입력한 경우
5분보다 오래된 파일은 .-gt-lt

관련 정보