Windows Batch Script Get Current Drive name

%CD% is what you're looking for. It prints the current working directory of the batch file or command running it. If your batch file is on the root of the drive, it will just print the drive letter, otherwise you'll have to parse the first 2 characters.

Example:

echo %CD%

prints

E:\

on a flash drive mounted to E:.

Update: As Andriy said in the comments, if you are just looking for the first three characters of the path, then use this instead of %CD%:

%CD:~0,3%

This will result in E:\, for example, anywhere on the drive.


M$ documentation "Using batch parameters" says:

Modifier: %~d0

Description: Expands %0 to a drive letter.


Beware

The existing answers to this question don't acknowledge that the question is actually asking about two different things:

  1. the drive of the current working directory (“Get Current Drive name”); and
  2. the drive of the batch file (“I need to know the drive name the batch is in”).

These can be different when the batch file is started from a working directory other than its residing location. Readers should therefore be clear on the difference before determining which solution is relevant to their case.

Drive of the current working directory

%CD:~0,2%

This takes the full current working directory and trims it down to the first two characters, which will be a drive letter and a colon, e.g. C:.

Drive of the batch file itself

%~d0

This trims the full path of the batch file (in %0) to just a drive letter and a colon, e.g. C:.


(this is an expanded version of my rejected edit to Kai K's answer)