0

Newbie problem.

For some reason, I can't get this to work:

FOR /L %%A IN (1 1 23) DO (
if %%A==1 set drive=C:
if %%A==2 set drive=D:
if %%A==3 set drive=E:
if %%A==4 set drive=F:
if %%A==5 set drive=G:
if %%A==6 set drive=H:
if %%A==7 set drive=I:
if %%A==8 set drive=J:
if %%A==9 set drive=K:
if %%A==10 set drive=L:
if %%A==11 set drive=M:
if %%A==12 set drive=N:
if %%A==13 set drive=O:
if %%A==14 set drive=P:
if %%A==15 set drive=Q:
if %%A==16 set drive=S:
if %%A==17 set drive=T:
if %%A==18 set drive=U:
if %%A==19 set drive=V:
if %%A==20 set drive=W:
if %%A==21 set drive=X:
if %%A==22 set drive=Y:
if %%A==23 set drive=Z:
echo %drive%
if NOT "%systemdrive%"=="%drive%" format /q %drive%
)

If I were to simply "echo foobar" rather than "set drive=Z:", it will do so correctly. It just will not set the variable :(

Suggestions?

Thanks!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by lastlight
1

Set is looking for a defined variable; "drive" is not defined in the command shell environment. You will have to create your variablename first, so at the head of your batchfile put this line:
set varname=drive
And it should then accept the set drive=x: lines.
Oh, and be careful of spaces - any after the = are part of the name.
You do realise that this will not be permanent? Your newly created variable "drive" will only exist in the current shell environment - you close it and it is gone.

Edited by gerbil: n/a

0

Yes, that worked. Thanks much :)

About the en-v being temp, that's what I would like. I'm erasing variables at the end of the batch anyways.

Once again, thanks for your help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.