I am very new to Windows batch scripting so please ignore if it is stupid question, I have a requirement of copying set of files from source to destination only if source file is modified after certain date_time, I managed to do it using XCOPY command.
XCOPY C:\Src\*.txt C:\Target /D /S /Y
This runs fine for first run, now the twist is once destination folder file is processed it will be renamed to some other name and extension, so when next time my script runs it does not find same file name as source in the destination folder because it is processed and renamed. So is there a way in XCOPY or any other Windows command to do the pattern match for the file name int the destination folder and if match found then proceed with date_time check and copy or else ignore?
Example Source Dir Files:
a.txt
b.txt
c.txt
Destination Dir Files After first script run:
a.txt
b.txt
c.txt
Destination Dir Files after processing and before running the script second time:
a_201603071130.ok
b_201603071130.ok
c_201603071130.ok
For second run of the script with XCOPY it does not find the file a.txt in destination as it is processed but the requirement is to copy only if a.txt file is modified after last run.
I can do this by storing the last run time and checking that for next run etc. but I wanted to find out if there is any other way of doing it.
XCOPY C:\Src\*.txt C:\Target /D /S /Y /M
The /M
switch changes the A
flag for the file.