Celeb Glow
updates | March 13, 2026

How to copy only new files from one folder to another AND only those that are added before 5 minutes only?

I would like to copy files from one drive to another, but I only want to copy source files that are newer than the destination file. BUT, I also want to only copy source files that have been changed in last 5 minutes.

I have created one file with .bat extension and used this command :

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

But this command is for date.

1

1 Answer

This PowerShell script:

(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"

wrapped in a batch file:

:: 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%\"
)

As is this will copy only files created/changed in the last 5 minutes, if I got that wrong,
and you mean files older than 5 minutes change the -gt to -lt.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy