I have a task to rename a file and place another file with same name in the same folder
Like for e.g. a folder C:/test
I have multiple files .txt
(suppose test.txt
is the one needed rename and replace)
I want to rename test.txt
to test_bkp%date%
and place new file there.
Need help to start the logic.
@ECHO OFF
SET "sourcedir=C:\Users\test\new"
FOR /f "delims=" %%a IN (
'dir /b /a-d "%C:\Users\Test\new\%filenames%.txt" '
) DO (
SET "filename=%%a"
ECHO REN "%C:\Users\Test\new\%%a C:\Users\Test\new\%%a_bk_date.*%"
)
GOTO :EOF
Let me explain what I am trying to achieve. I get file with updated data often. I cannot just go ahead and replace the old file with new. I have to take a backup and place the new file in the folder. This is my first try using batch scripting