Rob said:
You'll need to create two BAT files.
Pass the file you want to rename with date and time to RENDT.BAT
RENDT.BAT
(snip)
Hi
You can do it with only one batch file as well, using e.g the batch
date time functions from Ritchie Lawrence batch library available at
http://www.commandline.co.uk/lib
This works for me:
RENDT.BAT
--------------------8<----------------------
@echo off
if {%1}=={} goto syntax
if not exist %1 goto syntax
setlocal
call :GetDate year month day
call :GetTime hours mins secs hsecs
set filename=%1
set name=%~n1
set ext=%~x1
set newname=%name%(%year%%month%%day%_%hours%%mins%%secs%)
rename %filename% "%newname%%ext%"
endlocal
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetDate yy mm dd
::
:: By: Ritchie Lawrence, 2002-06-15. Version 1.0
::
:: Func: Loads local system date components into args 1 to 3. For NT4/2K/XP
::
:: Args: %1 var to receive year, 4 digits (by ref)
:: %2 var to receive month, 2 digits, 01 to 12 (by ref)
:: %3 Var to receive day of month, 2 digits, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f))
endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetTime hh nn ss tt
::
:: By: Ritchie Lawrence, updated 2002-10-30. Version 1.2
::
:: Func: Loads local system time components into args 1 to 4. For NT4/2K/XP
::
:: Args: %1 Var to receive hours, 2 digits, 00 to 23 (by ref)
:: %2 Var to receive minutes, 2 digits, 00 to 59 (by ref)
:: %3 Var to receive seconds, 2 digits, 00 to 59 (by ref)
:: %4 Var to receive centiseconds, 2 digits, 00 to 99 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d)
if 1%hh% LSS 20 set hh=0%hh%
endlocal&set %1=%hh%&set %2=%nn%&set %3=%ss%&set %4=%cs%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:syntax
echo/Syntax: Call RenDT filename
REM End of Rendt.bat
--------------------8<----------------------