Rename a Word file, replacing the date string with the current date

Viewed 29

I'm trying to use a batch script to rename a Word file, by replacing the date string it contains with the current date.

Ex: Notes_19-AUG-2022 to Notes_13-SEP-2022

Unfortunately, this script does not work, and I'm not sure why.

@echo off

rem 0,2 for mm/dd/yyyy or 3,2 for dd/mm/yyyy
set month-num=%date:~3,2%

rem remove any leading zero :
IF "%month-num:~0,1%"=="0" SET month-num=%month-num:~1%

FOR /f "tokens=%month-num%" %%a in ("jan feb mar apr may jun jul aug sep oct nov dec") do set mo-name=%%a
REN "C:\Users\Desktop\NOTES\Notes_19-AUG-2022" "C:\Users\Desktop\NOTES\Notes_%day%-mo-name%-%year%.docx"
0 Answers
Related