Solved Copy File - If Exists - Rename & Copy

September 14, 2017 at 08:37:29
Specs: Windows server 2016, Dell D630
Hello, I've created a batch file to copy a file from one location to another then sleep for a bit but I need the script to check and see if the file exists in the destination (which it will) and rename the original one or the new one being copied to a different name and keep doing that every loop but will need to increment the file name all the time so I will have a new file every time and all the others will be kept. This is what I have so far to do the copy but of course overwrites the destination every time :(
Thank you

:loop
copy file.log C:\folder\file.log
timeout 30
Goto loop


See More: Copy File - If Exists - Rename & Copy

Reply ↓  Report •

#1
September 14, 2017 at 10:07:13
✔ Best Answer
Actually, I'm just going to do the below which satisfies my needs; Thanks anyway

:loop
setlocal
set tm=%time: =0%
set tm=%tm::=%
set dt=%date:~10,4%%date:~4,2%%date:~7,2%
copy /Y File.log C:\bak\File%dt%%tm:~0,4%.txt
timeout 300
Goto loop


Reply ↓  Report •

#2
September 16, 2017 at 17:14:31
I don't see the option for "Select Best answer" so can't close the thread.

Reply ↓  Report •

#3
October 8, 2017 at 15:45:32
I use, Batch Rename Files Tool. You can easily found hier go to google.com and type BatchRenameFiles and check the first result that allows you to quickly rename all the files in a specified directory.

Reply ↓  Report •
Related Solutions


Ask Question