150

Is there a way to list the available drives from cmd.exe ? (Other than manually typying

c:
d:
...

and seeing which ones return errors)

12 Answers12

171
> 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 skip=1 option:

for /f "skip=1 delims=" %%x in ('wmic logicaldisk get caption') do @echo.%%x
Joey
  • 40,452
  • 2
    only for users with administrator rights – Carlos Campderrós Apr 16 '15 at 16:16
  • 1
    @CarlosCampderrós: works fine for me from a limited user account. – Joey Apr 16 '15 at 16:51
  • 1
    Quoting from https://support.microsoft.com/en-us/kb/290216 "Wmic.exe can only be used by the local system administrators regardless of WMI namespace permissions on the local machine", and it failed on my machine (a VM with winXP) – Carlos Campderrós Apr 17 '15 at 08:42
  • 4
    It worked just fine under a non-admin account on a Windows 8.1 here. Note that the KB article applies only to legacy operating systems. – Joey Apr 17 '15 at 10:33
  • 1
    @Joey, Why caption instead of wmic logicaldisk get name? – Pacerier Apr 23 '15 at 17:33
  • Got: Failed to register mof file(s). Only the administrator group members can use WMIC.EXE. Reason:Win32 Error: Access is denied. – Ajedi32 Jul 06 '15 at 17:18
  • This looks good too, including the volume name: wmic logicaldisk get caption,volumename. – kodybrown Jul 29 '15 at 15:35
  • doesn't work on MSDos – Tomáš Zato May 23 '16 at 08:28
  • @TomášZato: Of course not. The question was about the Windows command line (it even says so in both the title and the question), not MS DOS. – Joey May 23 '16 at 08:56
  • Use "NET USE" for listing the network mapped drives. – Francisco Luz Nov 30 '16 at 18:04
  • 'wmic' is not recognized as an internal or external command, – Karl Morrison Oct 01 '19 at 10:13
  • if I use for /f "skip=1 delims=" %%x in ('wmic DISKDRIVE get Model') do @echo.DISKDRIVE: %%x it prints out an additional line with DISKDRIVE: in it. I'm not sure how to fix this. Same with the original code, it prints an additional empty line to the cli. – Ste Jul 27 '20 at 15:58
  • I feel sad that this is considered the easiest way. Can you imagine if listing the current directory contents only had a command like this? – cowlinator Dec 01 '20 at 02:20
  • @cowlinator: Luckily for you, Get-PSDrive is a much shorter way in PowerShell. By now, cmd can be considered mostly obsolete. – Joey Dec 02 '20 at 16:44
  • @Joey, ah, I see. I thought that the -psprovider filesystem args were an absolute requirement. Yes, get-psdrive is the simplest way. – cowlinator Dec 04 '20 at 00:37
  • This is really helpful for me to find the correct volume, thanks! – Darryl RN Aug 31 '23 at 10:00
92

If you're in Command Prompt:

diskpart

then

list volume

sample output:

  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

and finally

exit

to return to the command line.

36

For the sake of completeness, there is yet another way:

fsutil fsinfo drives

which returns:

Drives: C:\ D:\ E:\ F:\

(Not a very scripting-friendly output, but it may be useful for human eye)

Some reference. That should work since win2k but only with Administrator account.

(Thanks @Carlos Campderrós for enhancing the answer)

saulius2
  • 571
  • 5
    It should be noted that this only work if you are using an Administrator account – Carlos Campderrós Apr 16 '15 at 16:11
  • 2
    @CarlosCampderrós I don't think that's correct. I can run fsutil with a limited user, and the result is much faster than spinning up the wmic system. On my box with only SSDs running windows 10 v 1803, wmic takes 100-200ms, and fsutil takes ~20ms. – mrm Sep 20 '18 at 18:24
  • 1
    @mrm, some windows version (or release, or build of w10) probably losened this restriction. I tested this on wxp and w7pro, and it failed without an admin account (AFAIR). – saulius2 Sep 20 '18 at 18:48
  • 1
    I second the observation by @saulius2 – Fr0zenFyr Jul 18 '19 at 04:46
14

If you're using powershell then you can type in

get-psdrive -psprovider filesystem

Edited in response to comments to only show filesystems

  • 1
    That will also return other non-filesystem drives that are mounted, such as Cert:, Alias: and Function:. Furthermore, it will return other file-system directories mounted as a PSDrive (such as Home: for %UserProfile% for me). – Joey May 11 '10 at 13:31
  • 1
    This is the only answer that worked for me. All other solutions seem to require administrator access. (At least on my horribly outdated Windows XP system.) – Ajedi32 Jul 06 '15 at 17:22
  • 1
    You can just use get-psdrive if you don't mind seeing non-filesystem drives listed. – cowlinator Dec 04 '20 at 00:36
12
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 /?

then

wmic logicaldisk get /?
  • I was trying to get the drive letter of the CD/DVD ROM and the closest thing I could find to get that is wmic logicaldisk get name,filesystem. Normal drives will list as NTFS or FAT32, and the CD/DVD ROM's filesystem will be empty. – akinuri May 13 '18 at 13:51
  • Correction: if the drive is empty, filesystem is empty. If not, e.g. I have Windows 10 disc in it at the moment, and it's listed as UDF. – akinuri May 13 '18 at 13:58
8

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.

5

To see available drives and their mount points from the cli I use

mountvol

You can also use the unmounted volume GUID for some commands like chkdsk and stuff.

Lucas
  • 51
  • What Windows versions have you used it on? On w10 [Version 10.0.19042.1348] it shows me only a help screen, sadly. – saulius2 Dec 03 '21 at 09:43
  • scroll down. it's listed after the help. it took me a few minute to realize it. by reflex, we tend to start reading right after where we typed the command. – e-Fungus Oct 31 '23 at 14:33
4

When you're using powershell, you can use the simple command

get-volume

and get a nice list with 8 columns:

DriveLetter Label FileSystem DriveType Health OperStatus FreeSpace Size

I write 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).

sudodus
  • 145
2

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 C:\ where name shows like C.

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
)
Giacomo1968
  • 55,001
Wasif
  • 8,474
  • You shouldn’t post three separate answers for three different methods. I took the answers you posted here as well as here and combined them in this answer. – Giacomo1968 Jan 05 '22 at 17:45
1

my approach would be a batch file with a standalone single command, (not external command needed)...

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 %%v:
1

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 [1] that would contain the full set of capital letters in order to shorten the for command's length.

Since 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:

C:
D:

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 (::).

Batch File

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 [1]=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 (%[1]%) 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.)

Giacomo1968
  • 55,001
  • Hi, I'm new to answering. After I pasted a batch code, lines ran into each other and Giacomo fixed it. If I pasted batch code in a Code Block will that preserve my original spacing? --Bill – Billy-Boy Jan 06 '22 at 17:45
  • Thanks for noting the DVD exception. – saulius2 May 11 '22 at 06:11
0

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...