Batch file to save current drive letter into a variable

Posted on 2006-07-13
Last Modified: 2012-05-05
I would like to be able to do something like this: command %driveletter% . Any help is appreciated.

Question by:gromul
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

rage419 earned 500 total points
ID: 17105353
How about using the %cd% variable and set? Seems to work...

set bob=%cd:~0,1%

LVL 43

Expert Comment

by:Steve Knight
ID: 17106326
Or for NT4 I have had to use this as %CD% doesn't work until 2000 (which therefore works on NT/2000/XP/2003):

for /f "tokens=*" %A in ('CD') do set DRIVE=%~dA

Expert Comment

ID: 17109713

If you are using XP you can use these:


Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question