user3901114
user3901114

Reputation: 23

Get the drive letter of a given volume?

Given a hard drive volume name how can I get the drive letter using a batch file in Windows 7?

Upvotes: 2

Views: 564

Answers (2)

David
David

Reputation: 6571

Using :

Get-WMIObject Win32_logicaldisk | where {$_.volumename -eq "<volumename>"} | select DeviceID

Upvotes: 2

Magoo
Magoo

Reputation: 79982

@ECHO OFF
SETLOCAL
SET "volname=System Reserved"
FOR %%d IN (Z Y X W V U T S R Q P O N M L K J I H G F E D C B A) DO IF EXIST %%d:\. (
 FOR /f "tokens=5*" %%L IN ('VOL %%d:^|FIND /i "drive"'
  ) DO IF "%%L"=="is" IF "%%M"=="%volname%" ECHO %%d is %%M
)
GOTO :EOF

Demonstrating how to find driveletters with volumename System Reserved.

Upvotes: 0

Related Questions