Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for drivused.bat

(view source code of drivused.bat as plain text)

  1. @ECHO OFF
  2. ECHO.
  3.  
  4. :: Check OS version (Windows XP or later)
  5. IF NOT "%OS%"=="Windows_NT"       GOTO Syntax
  6. VER | FIND "Windows NT"   >NUL && GOTO Syntax
  7. VER | FIND "Windows 2000" >NUL && GOTO Syntax
  8.  
  9. :: Check command line arguments (none required)
  10. IF NOT  "%~1"=="" GOTO Syntax
  11.  
  12. :: Allow delayed variable expansion
  13. SETLOCAL ENABLEDELAYEDEXPANSION
  14. SET Available=
  15. SET Drives=
  16.  
  17. :: The main command to list all drive letters in use is FSUTIL FSINFO DRIVES.
  18. :: MORE /E /T0 removes the vertical tabs/single linefeeds from FSUTIL's output,
  19. :: which is necessary to allow parsing with FOR /F.
  20. FOR /F "tokens=1,2 delims=\ " %%A IN ('FSUTIL FSINFO DRIVES ^| MORE /E /T0') DO (
  21. 	IF "%%B"=="" (
  22. 		SET Drives=!Drives! %%A
  23. 	) ELSE (
  24. 		SET Drives=%%B
  25. 	)
  26. )
  27. :: Display the formated result
  28. ECHO Drive letters in use      %Drives%
  29.  
  30. :: Check which drive letters are not in use
  31. FOR %%A 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 (
  32. 	ECHO.%Drives% | FIND "%%A:" >NUL
  33. 	IF ERRORLEVEL 1 (
  34. 		IF "!Available!"=="" (
  35. 			SET Available=%%A:
  36. 		) ELSE (
  37. 			SET Available=!Available! %%A:
  38. 		)
  39. 	)
  40. )
  41. :: Display the formated result
  42. ECHO Available drive letters   %Available%
  43.  
  44. :: "Export" the 2 variables and terminate
  45. ENDLOCAL & SET Drives=%Drives%& SET Available=%Available%
  46. GOTO:EOF
  47.  
  48.  
  49. :Syntax
  50. ECHO DrivUsed.bat,  Version 1.00 for Windows XP and later
  51. ECHO List used and available drive letters
  52. ECHO.
  53. ECHO Usage:  DRIVUSED
  54. ECHO.
  55. ECHO Note:   The list of drive letters in use is displayed on screen
  56. ECHO         and stored in an environment variable named "Drives".
  57. ECHO         The list of available drive letters is displayed on screen
  58. ECHO         and stored in an environment variable named "Available".
  59. ECHO.
  60. ECHO Written by Rob van der Woude
  61. ECHO http://www.robvanderwoude.com
  62.  

page last modified: 2024-04-16; loaded in 0.0095 seconds