Question : Rename Batch File does not work on Windows 2003 Server, but it does on Windows XP?

I am writting a batch file to rename a backup file and move it to the archive directory.  For some reason the batch works fine when tested on Windows XP PRO box.  When I move it to the Windows 2003 Server, it will not rename the file correctly.  It will rename the file to -03-2007-backup803.1, when it should be 2007-03-15-backup803.1.  Some helpe would be apprieciated!  Thanks

@echo off

for /f "tokens=1,2,3,4 delims=/ " %%a in ('date /t') do set today=%%c-%%b-%%d
RENAME d:\backup\backup803.1 "%today%"-backup803.1

move d:\backup\"%today%"-backup803.1 d:\backup\Z_DAILY_BACKUPS

Answer : Rename Batch File does not work on Windows 2003 Server, but it does on Windows XP?

This will work on both systems:

@echo off

setlocal

call :GETDATEPARTS "%date%"

set today=%yy%-%mm%-%dd%

RENAME "d:\backup\backup803.1" "%today%-backup803.1"

move "d:\backup\%today%-backup803.1" "d:\backup\Z_DAILY_BACKUPS"

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF
Random Solutions  
 
programming4us programming4us