Hi,
My problem is as follows.
I have 2 directories software_test_R1.1 and software_test_R1.2 contained with a parent directory called test
My code is as follows
@echo off
for /f "tokens=* delims=" %%X in ('dir /ad /b') do (
for /f "tokens=3 delims=_" %%A IN ("%%X") do (
echo %%A
set version=%%A
echo %version%
)
)
I expected that within second for loop that echo %%A would give me the same value as echo %version%
What i get is
software_test_R1.1
R1.1
R1.2
software_test_R1.2
R1.2
R1.2
Does anyone know the fix for this ?
Thanks
setting variable within for loop
Moderator: DosItHelp
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: setting variable within for loop
Didn't really look too closely but, try this:
Code: Select all
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "tokens=* delims=" %%X in ('dir /ad /b') do (
for /f "tokens=3 delims=_" %%A IN ("%%X") do (
echo %%A
set version=%%A
echo !version!
)