I need to create a backup batch script for a directory. It will update every 10 minutes. I would like it to only update files that have been added to the directory or modified after the last backup.
I tried to use this script:
@ECHO OFF
SET srcdir=D:\Source
SET tgtdir=D:\Target
SET /A topcnt=3
SET /A cnt=0
FOR /F "tokens=*" %%F IN ('DIR /A-D /OD /TW /B "%srcdir%"') DO (
SET /A cnt+=1
SETLOCAL EnableDelayedExpansion
IF !cnt! GTR !topcnt! (ENDLOCAL & GOTO :EOF)
ENDLOCAL
COPY "%srcdir%\%%F" "%tgtdir%"
)
The problems I have is that it only works in the directory that the batch file is in, which will return the most recent three files including the batch file itself. Additionally, the copy function is not working. The program is not connecting the srcdir with the file extension, thus the program cannot determine what file to copy. Please advise.