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

1
  • 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, Commented Jul 15, 2013 at 7:46

1 Answer 1

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!=%%"
)
Sign up to request clarification or add additional context in comments.

1 Comment

wah you are batch GODLIKE, this is second time u solved my problem with very specific answer, many thanks, ~god bless u @Endoro~

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.