|
|
Cry How To...List drive letters in a batch file or in a command windowAt the command promptThere are at least two ways of getting a list of drive letters when working at the command prompt. 1. The simplest is to use WMIC, for example: wmic logicaldisk get description,name which on my PC produces: C:\>wmic logicaldisk get description,name If I only wanted to list my local fixed disks I would instead use: wmic logicaldisk where drivetype=3 get description,name and this would produce: C:\>wmic logicaldisk where drivetype=3 get description,name If you specify the "drivetype" the different values you can use are:
2. An alternative is to use fsutil fsinfo drives which on my PC produces: C:\>fsutil fsinfo drives Drives: C:\ D:\ E:\ F:\ G:\ H:\ Z:\ As you can see the output is different, For more information on In a batch fileFor a batch file I prefer to use wmic simply because it does not require elevated privileges. The following when copied into a batch/command file will simply echo the drive letters: @echo off Note that the "for" line should all be on one line - despite how it might be wrapped in the browser window. When using this for real you will probably want to replace the echo with a call to do something on the drive. These notes have been tested with Windows Vista and may also apply to other versions of Windows. About the author: Brian Cryer is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant. |