2

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

paiseha
  • 169
  • 1
  • 3
  • 10
  • before that, here is original code of string replacement that i refer to @echo off set string=This is my string to work with. set string=%string:to work with.=% echo %string% Output = This is my string base on it, i need to initialize value "to work with." into string variable since i need to use it in loop, so thats the mess, – paiseha Jul 15 '13 at 07:46

1 Answers1

3

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!=%%"
)
Endoro
  • 37,015
  • 8
  • 50
  • 63
  • wah you are batch GODLIKE, this is second time u solved my problem with very specific answer, many thanks, ~god bless u @Endoro~ – paiseha Jul 15 '13 at 07:54