Is there a way to list the available drives from cmd.exe ? (Other than manually typying
c: d: ...
and seeing which ones return errors)
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
> wmic logicaldisk get caption Caption C: D: E:
if probably the easiest one. Doesn't need administrative privileges, doesn't return more or less than what's needed, etc.
If you want to use it in a script, then wrap it in
for /f with the
for /f "skip=1 delims=" %%x in ('wmic logicaldisk get caption') do @echo.%%x
If you're in Command Prompt:
Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- -------- Volume 0 E DVD-ROM 0 B No Media Volume 1 System Rese NTFS Partition 100 MB Healthy System Volume 2 C System NTFS Partition 99 GB Healthy Boot Volume 3 F Data (local NTFS Partition 365 GB Healthy
to return to the command line.
For the sake of completeness, there is yet another way:
fsutil fsinfo drives
Drives: C:\ D:\ E:\ F:\
(Not a very scripting-friendly output, but it may be useful for human eye)
(Thanks @Carlos Campderrós for enhancing the answer)
wmic logicaldisk get volumename,name
You can get (query) multiple properties this way. This will give you the partition/drive letter and the label you gave the drive/partition when you formatted the drive:
Name VolumeName C: OS D: Data E: Programs
For help and to list all the permission options:
wmic logicaldisk /?
wmic logicaldisk get /?
When you're using powershell, you can use the simple command
and get a nice list with 8 columns:
DriveLetter Label FileSystem DriveType Health OperStatus FreeSpace Size
Label where get-volume writes
FriendlyName (and I have abbreviated some of the titles in the list in order to minimize the risk of scrolling horizontally to see the end of the line).
In VBscript we can use:
Dim fso,colDrives,objDrive Set fso = CreateObject("Scripting.FileSystemObject") Set colDrives = fso.Drives For Each objDrive in colDrives Wscript.Echo "Drive letter: " & objDrive.DriveLetter Next
In Powershell you can list drives inside an array with:
$drives=gdr -psp FileSystem|select -eXp root
Here it selects
root property which shows like
name shows like
To iterate over drives in batch you can use:
@echo off for /f "tokens=2 delims==" %%a in ('wmic logicalDisk get caption /format:List ^| find /I "caption"') do ( echo %%~a is your drive letter echo Do what you like here )
I absolutely love the pure batch method shown in the answer from cybercontroler, all internal commands no less!
I wanted to share my batch edit/modification that based on cybercontroler's answer.
For my current project, I needed to identify which drive labeled as
DATA so I replaced the echo command with vol (internal command).
I also used the set command to create the variable
 that would contain the full set of capital letters in order to shorten the
for command's length.
if exist will be checking for drive letters only, there will never be a space character in this test, so I omitted the double quotes.
Testing the omission the two back slashes yields the same results.
The added command line
@echo off filtered the output to show results only.
I piped the results to the external
find command to filter serial number lines created by the vol command.
I placed a pause command so that it wouldn't be necessary to run a "Command Prompt" beforehand in order to see the results when clicking on the batch file.
The results from the original identified all available drive letters mixed in with
for command processing the full set of capital letters. With
@echo off filtering, my run displayed:
The results using vol displays: Volume in drive C is OS
Volume in drive D is DATA Press any key to continue . . .
Here's my batch file which includes both for commands; you can comment-out the for command that you do not want to run by prefixing command lines with two colons (
echo Available Drives: for %%v in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist "%%v:\\" echo %%-: @echo off set =A B C D E F G H I J K L M N O P Q R S T U V W X Y Z for %%- in (%%) do if exist %%-: vol %%-: | find "in drive" pause
Note that this batch method does not identify DVD drives, not sure why. But the command
fsutil fsinfo drives does. My output reads:
Drives: C:\ D;\ J:\ (
J:\ being my DVD drive.)
Thanks @Billy-Boy I didn't thought about that "if exist" wouldn't work with an empty CD/DVD/Card-Reader/etc. drives, it is because "if exist" work on files or directories level, so in empty drives exist nothing, (long time I do not use CD drives)... for the use I need I don't mind empty drives, but would be nice having a code that show empty drives also, although it, for sure, would be not that minimalist...