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)
If you're using powershell then you can type in
get-psdrive -psprovider filesystem
Edited in response to comments to only show filesystems
Use the doskey built in function to create an alias that runs the wmic command with the necessary atributes
doskey v=wmic logicaldisk get caption
This will create an aliases "v" that whenever typed will run the given command and list all volume letters.
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 /?