Suppose I have two directories: N:\test1 and N:\archive
.
I want to move any .csv files from test1 to archive.
I want to archive the files, as now they are being overwritten, so I thought of adding a timestamp.
I am following some sort of logic like this so far, but not sure how do I append the timestamp to the file name:
REM TimeStamp
for /f "tokens=2-8 delims=.:/ " %%a in ("%date% %time%") do set DateNtime=%%c-%%a-%%b_%%d%%e%%f
REM move the file
move /Y N:\test1\*.csv N:\archive
REM Rename the file with timestamp
ren N:\archive\*.csv *_%DateNtime%.csv
This is the part I´m stuck at: ren N:\archive\*.csv *_%DateNtime%.csv
As you can imagine, there'll be existing .csv archived files from the first time, so how do I tell it to rename the file the was just moved?
For example, suppose there's file1.csv in test1 folder. After it's moved to archive, it should be renamed to file1_%DateNtime%.csv
.
Note: N:\ is a UNC/mounted shared drive