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 :(



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.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.