I need to have a batch script to apend a date stamp to a file, does any one have any ideas. For exampe if I have a file "HELLO" i need to make it "HELLO.MMDDYYHHMM"
If you're using UK format date/time, the following will work. Save it as something like rendate.bat
If you're using other date formats, use "echo %date%" and "echo %time%" to work out which variables to change.
The :~0,2 means start at character 0 for 2 characters.
The %-2 means use the last two characters.
--------------------
if "%1"=="" goto :usage
if not exist "%1" goto :notexist
set d=%date:~0,2%
set m=%date:~3,2%
set y=%date:~-2%
set hh=%time:~0,2%
set mm=%time:~3,2%
rename %1 %1.%m%%d%%y%%hh%%mm%
goto :EOF
:usage
echo Usage: %~n0 ^<filename^>
goto :EOF
:notexist
echo %1 does not exist.
goto :EOF
----------------------
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.