Answer» I need help trying to get just the Drive letter in batch files. So far the best I can come up with is this REM get CURRENT location set origdir=%cd% REM get to root of the drive and save that location cd\ set odrive=%cd% REM return to original location cd %origdir% REM strip :\ off the current drive if %odrive%==A:\ set odrive=A if %odrive%==B:\ set odrive=B if %odrive%==C:\ set odrive=C if %odrive%==D:\ set odrive=D if %odrive%==E:\ set odrive=E if %odrive%==F:\ set odrive=F if %odrive%==G:\ set odrive=G if %odrive%==H:\ set odrive=H if %odrive%==I:\ set odrive=I if %odrive%==J:\ set odrive=J if %odrive%==K:\ set odrive=K if %odrive%==L:\ set odrive=L if %odrive%==M:\ set odrive=M if %odrive%==N:\ set odrive=N if %odrive%==O:\ set odrive=O if %odrive%==P:\ set odrive=P if %odrive%==Q:\ set odrive=Q if %odrive%==R:\ set odrive=R if %odrive%==S:\ set odrive=S if %odrive%==T:\ set odrive=T if %odrive%==U:\ set odrive=U if %odrive%==V:\ set odrive=V if %odrive%==W:\ set odrive=W if %odrive%==X:\ set odrive=X if %odrive%==Y:\ set odrive=Y if %odrive%==Z:\ set odrive=Z
I was hopeing there might be an easier way to just get the letter. I have tried a for command but being partly self taught I am haveing trouble getting the for command to work in tests. Any help or simpler codeing for win XP sp2 would be most welcome. REPLACE the whole line of IF statements with this:
SET odrive=%odrive:~0,2%Thank you So Much I knew if i asked the right people or looked on the right web page I would get an easy answer . I have been banging my head agenst that problem for 2 days searching the net . I will be back when i NEXT get in trouble with my batch programingEasy? Nah, it took me a YEAR to learn that. You're welcome, by the way.
|