Posted By

Scooter on 09/04/09


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

sulfurito
Tyster
thastyle


Get list of drive letters and labels


 / Published in: DOS Batch
 

URL: http://serverfault.com/questions/62578/

Someone on Serverfault was asking for a Batch script to get a list of drive letters and their associated labels on a windows system. This is my suggested answer.

  1. @ECHO OFF
  2. :A
  3. VOL A:
  4. :B
  5. VOL B:
  6. :C
  7. VOL C:
  8. :D
  9. VOL D:
  10. :E
  11. VOL E:
  12. :F
  13. VOL F:
  14. :G
  15. VOL G:
  16. :H
  17. VOL H:
  18. :I
  19. VOL I:
  20. :J
  21. VOL J:
  22. :K
  23. VOL K:
  24. :L
  25. VOL L:
  26. :M
  27. VOL M:
  28. :N
  29. VOL N:
  30. :O
  31. VOL O:
  32. :P
  33. VOL P:
  34. :Q
  35. VOL Q:
  36. :R
  37. VOL R:
  38. :S
  39. VOL S:
  40. :T
  41. VOL T:
  42. :U
  43. VOL U:
  44. :V
  45. VOL V:
  46. :W
  47. VOL W:
  48. :X
  49. VOL X:
  50. :Y
  51. VOL Y:
  52. :Z
  53. IF NOT EXIST Z: GOTO END
  54. VOL Z:
  55. :END

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: erniedobsonmaycroftnet on March 3, 2010

This fails for Winbond devices assigned a drive letter but no media is loaded. Message Windows - No Disk Excpetion Processing messaage ....................................

Cancel TryAgain Continue Using the original idear i have created on the will display drive lettters or Vol information @echo off set INFO=%1

call :Drive 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

goto :EOF

:Drive vol %1: > nul 2>nul If ERRORLEVEL 1 goto Next

if not "X"%INFO%=="X" (vol %1:) else echo %1: :Next shift if NOT "X"%1=="X" goto :Drive

Posted By: erniedobsonmaycroftnet on March 3, 2010

@echo off

rem Vol information is displayed if called with an argument, otherwise the drive letters are displayed

set INFO=%1

call :Drive 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 set INFO= goto :EOF

:Drive vol %1: > nul 2>nul If ERRORLEVEL 1 goto Next

if not "X"%INFO%=="X" (vol %1:) else echo %1: :Next shift if NOT "X"%1=="X" goto :Drive

Posted By: erniedobsonmaycroftnet on March 3, 2010

@echo off

rem Vol information is displayed if called with an argument, otherwise the drive letters are displayed

set INFO=%1

call :Drive 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 set INFO= goto :EOF

:Drive vol %1: > nul 2>nul If ERRORLEVEL 1 goto Next

if not "X"%INFO%=="X" (vol %1:) else echo %1: :Next shift if NOT "X"%1=="X" goto :Drive

Posted By: erniedobsonmaycroftnet on March 3, 2010

@echo off

rem Vol information is displayed if called with an argument, otherwise the drive letters are displayed

set INFO=%1

call :Drive 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 set INFO= goto :EOF

:Drive vol %1: > nul 2>nul If ERRORLEVEL 1 goto Next

if not "X"%INFO%=="X" (vol %1:) else echo %1: :Next shift if NOT "X"%1=="X" goto :Drive

Posted By: erniedobson on March 4, 2010

This fails for Winbond devices assigned a drive letter but no media is loaded. Message Windows - No Disk Excepetion Processing messaage .................................... Cancel TryAgain Continue

To find a better version search for list drives letters or volume details

You need to login to post a comment.