Using variables with the rename command in a batch file

  • Thread starter Thread starter pww2
  • Start date Start date
P

pww2

Guest
Hello,

I am trying to use variables in renaming a robocopy log file but I continually receive a 'syntax error'. Everything works perfectly until I use the rename command. I am using the latest build of Windows 10. Any advice will be appreciated, thank you. The batch file script is as follows:


@echo off​

REM set date stamp​

for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a​

set YY=%dt:~0,2%​

set MM=%dt:~4,2%​

set DD=%dt:~6,2%​

set stamp=%YY%%MM%%DD%​


REM set variables

set fname=placeHolder​

set source="C:\Me\SrcPath\%fname%"​

set target="C:\Me\tgtPath\%fname%"​

set project=ListMake​

set tempLog="C:\Me\LogFiles\temp.log"​

set finalLog="C:\Me\LogFiles\log%project%Backup%stamp%.log"​


Rem use robocopy to to copy src folders to tgt folder and log data in temp log​


Rem copy src1 folder

set fname=src1​

Robocopy %source% %target% /MIR /XA:SH /XD AppData /XJD /R:5 /W:15 /MT:32 /V /NP /LOG+:%tempLog%​


REM Copy src2 folder

set fname=src2​

Robocopy %source% %target% /MIR /XA:SH /XD AppData /XJD /R:5 /W:15 /MT:32 /V /NP /LOG+:%tempLog%​


REM************The rename below is where I continuously get an error.

REM************I have tried setting variable values with and without quotes

REM************as well as trying the rename command with and without quotes around the variables

REM************no matter which permutation I use the batch file returns a syntax error during rename


ren %tempLog% %finalLog% /q



Pause​

Continue reading...
 
Back
Top