I need to copy files at a regular interval, eg once an hour so I tried setting up an xcopy batch saying it should copy the files it needs to copy to another folder. Now when it copies, it overwrites the files which is not what it is supposed to do.
When a file is copied, it should create a new file instead, named something like File.txt, File-COPY1.txt, File-COPY2.txt or something like that.
Any way to do that?
Thanks in advance.
You can create individual files for each run by simply adding a time stamp to the file name. Something like this:
XCOPY "File.txt" "[TargetDir]\File1_%time:~0,2%_%time:~3,2%_%time:~6,2%.txt"
This resolves to a file name that reads as File1_11_30_05.txt
given that the copy operation takes place at 11:30:05. The %time:~0,2%
part extracts 2 digits from the time string stored in the variable %time%
.
In addition you could also add the date in the same fashion. You can use the variable %date%
for this purpose.
If you really need a pattern like File-COPY1.txt
, File-COPY2.txt
etc. This needs a bit more work. Tell us if the time stamp approach is not sufficient.