There must be a better way to write this batch file?

TechnoPro

Golden Member
Jul 10, 2003
1,727
0
76
I wrote a simple script that we use to detect the presence of certain directories and files and then perform certain tasks accordingly. By virtue of the mixed computer setup in the office, this directory can exist on any drive letter from C-Z. So this script manually checks each one.

IF EXIST "C:\%SPECIAL_PATH%" (SET LOCAL_DRIVE=C& GOTO CREATE) ELSE (ECHO.)

IF EXIST "D:\%SPECIAL_PATH%" (SET LOCAL_DRIVE=D& GOTO CREATE) ELSE (ECHO.)

IF EXIST "E:\%SPECIAL_PATH%" (SET LOCAL_DRIVE=E& GOTO CREATE) ELSE (ECHO.)

...

IF EXIST "Z:\%SPECIAL_PATH%" (SET LOCAL_DRIVE=Z& GOTO CREATE) ELSE (ECHO.)

Is there a cleaner way of writing this out? Like somehow setting a range of values b-z? I'm very grateful for any suggestions.
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
You didn't specify which OS, but on Windows XP (2K also) you should be able to build something from:

for %x in (a,b,c,d,e,f,g,h) do echo %x

In an actual batch file the %x should be %%x

Bill
 

TechnoPro

Golden Member
Jul 10, 2003
1,727
0
76
Originally posted by: bsobel
You didn't specify which OS, but on Windows XP (2K also) you should be able to build something from:

for %x in (a,b,c,d,e,f,g,h) do echo %x

In an actual batch file the %x should be %%x

Bill

What a lifesaver you are, thank you! That works like a charm! Drinks are on me if you're ever in my neck of the woods.