Computing.Net > Forums > Windows 2000 > variable inside for-loop( batch )

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

variable inside for-loop( batch )

Reply to Message Icon

Name: taiwf
Date: September 22, 2005 at 17:58:53 Pacific
OS: win2k
CPU/Ram: p4 celeron/512Mb
Comment:

I am try to access a environmental variable i SET inside the batch for loop. But i can't seem to acess it even tho its actually already existed (i pause the forloop and test it on anther cmd screen).
Can anyone please help me about it?

Below is the script.

:: I name my usb hard disk with bracket, ie.(hard-disk-Name)
::-----------------------

for /f "token=2 delmis=(*)" %%A IN ('vol e: f: g: 2^>NUL') do (
SET hd_name=%%A
echo %hd_name%
)

::-------------------------



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: September 22, 2005 at 20:38:58 Pacific
Reply:

I couldn't make yours work, so I re-wrote it.

Note that the variable is NOT available in a different command shell.

HTH

:::::::::
@echo off

for /f "tokens=*" %%A IN ('vol c: e: u: ^|find "drive"') do call :sub1 %%A
goto :eof

:sub1

SET hd_name=%6
echo %hd_name%
goto :eof
:::::::::::::::


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: taiwf
Date: September 22, 2005 at 22:37:38 Pacific
Reply:

I think the problem is whenever i try to do arithmatic inside () , it just won't work!

I try this and somehow the line outside bracket give me correct answer and inside 1+1 always give me 1 not 2...

SET ROT_COUNTER=1
if %ROT_COUNTER% LEQ 2 (
SET /a ROT_COUNTER=%ROT_COUNTER%+1
echo "ROT_counter less or equal to 2"
echo %ROT_COUNTER%
) else (
SET /a ROT_COUNTER=1
echo %ROT_COUNTER%
)

SET /a ROT_COUNTER+=1
echo %ROT_COUNTER%

SET ROT_COUNTER=


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Allowing only certain web... Inaccessible Boot Device



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows 2000 Forum Home


Sponsored links

Ads by Google


Results for: variable inside for-loop( batch )

GOTO command inside a FOR loop www.computing.net/answers/windows-2000/goto-command-inside-a-for-loop/65812.html

for loop emtpy str detection www.computing.net/answers/windows-2000/for-loop-emtpy-str-detection/63106.html

cutting from variable in for loop www.computing.net/answers/windows-2000/cutting-from-variable-in-for-loop/62959.html