Question

im beginner, my task is something to do with renaming files in folder, first of all here is a piece of my code:-

setlocal enabledelayedexpansion
set tempLogDate=0
set g=0

for /r %targetStore% %%i IN (*2013*.*) do (
  set tempLogDate=9
  set g=!g:%tempLogDate%=!
)

the problem is variable %tempLogDate% value is 0 instead of 9, i know i need to use variable expansion(which i have) but i cant replace code "set g=!g:%tempLogDate%.rar=!" to "set g=!g:!tempLogDate!.rar=!", i try escape character but no result, guys pls help me..thanks in advance

Was it helpful?

Solution

Please look for delayed expansion, setlocal /? and endlocal /?. Example:

@ECHO OFF &setlocal enabledelayedexpansion
set "tempLogDate=0"
set "g=0"

for /r %targetStore% %%i IN (*2013*.*) do (
  set "tempLogDate=9"
  CALL SET "g=%%g:!tempLogDate!=%%"
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top