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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)