I Run a batch file which saves as a filename.txt format but I need to know how to provide command which saves as filename_dd/mm/yy.txt format.
For Example I need it to save as Superuser_10-Oct-2016.txt format.
Please Help.
I Run a batch file which saves as a filename.txt format but I need to know how to provide command which saves as filename_dd/mm/yy.txt format.
For Example I need it to save as Superuser_10-Oct-2016.txt format.
Please Help.
You can use %date% that would give you something like 2016-10-12 (year-month-day). Now you just need to asign that to different variables by doing:
set day=%date:~8,2%
set month=%date:~5,2%
set year=%date:~0,4%
then you just need to get that into the filename. And as you can't use "/" in a command i use "-":
echo "text goes here" >> filename_%day%-%month%-%year%.txt
And Voila!
And if you want to use the names for the months and not the numbers:
if %monthc%==1 set month=Jan
if %monthc%==2 set month=Feb
if %monthc%==3 set month=Mar
if %monthc%==4 set month=Apr
if %monthc%==5 set month=May
if %monthc%==6 set month=Jun
if %monthc%==7 set month=Jul
if %monthc%==8 set month=Aug
if %monthc%==9 set month=Sep
if %monthc%==10 set month=Oct
if %monthc%==11 set month=Nov
if %monthc%==12 set month=Dec
Just be sure to add a c to the end of the first set command (the one with: "set month=%date:~5,2%)