-1

I meet a problem about batch in windows. The following codes can run well in a bat file.

set word1=
set word2=
set str=I0338092020061201B.zip.Z
call set str=%%str:2006=%word1%%%
call set str=%%str:B.zip.Z=%word2%%%
echo %str%

But the problem is when the codes embedded into the loop, the parameter str return null.

set word1=
set word2=
For /R %cd%\FX\ %%G IN (*.txt) do (
    Echo "%%G"
    set str=IXXXXX2020061201B.zip
    call set str=%%str:2006=%word1%%%
    call set str=%%str:B.zip=%word2%%%
    echo %str%
    timeout 1
)

Is there any method to cover that, and why it happened this way. Thanks a lot.

abramhum
  • 443
  • 2
  • 8
  • 20

1 Answers1

0

I find out the answer and the solution is as following:

setlocal enabledelayedexpansion
For /R %cd%\FX\ %%G IN (*.txt) do (
set tmp=%%G
set tmp=!tmp:%cd%\FX\200612=!
set tmp=!tmp:.txt=!
echo %%G
echo !str!
)
endlocal

Thanks

abramhum
  • 443
  • 2
  • 8
  • 20