(view source code of drivused.bat as plain text)
@ECHO OFF
ECHO.
:: Check OS version (Windows XP or later)IF NOT "%OS%"=="Windows_NT" GOTO Syntax
VER | FIND "Windows NT" >NUL && GOTO Syntax
VER | FIND "Windows 2000" >NUL && GOTO Syntax
:: Check command line arguments (none required)IF NOT "%~1"=="" GOTO Syntax
:: Allow delayed variable expansionSETLOCAL ENABLEDELAYEDEXPANSION
SET Available=
SET Drives=
:: The main command to list all drive letters in use is FSUTIL FSINFO DRIVES.:: MORE /E /T0 removes the vertical tabs/single linefeeds from FSUTIL's output,:: which is necessary to allow parsing with FOR /F.FOR /F "tokens=1,2 delims=\ " %%A IN ('FSUTIL FSINFO DRIVES ^| MORE /E /T0') DO (
IF "%%B"=="" (
SET Drives=!Drives! %%A
) ELSE (
SET Drives=%%B
)):: Display the formated resultECHO Drive letters in use %Drives%
:: Check which drive letters are not in useFOR %%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 (
ECHO.%Drives% | FIND "%%A:" >NUL
IF ERRORLEVEL 1 (
IF "!Available!"=="" (
SET Available=%%A:
) ELSE (
SET Available=!Available! %%A:
) )):: Display the formated resultECHO Available drive letters %Available%
:: "Export" the 2 variables and terminateENDLOCAL & SET Drives=%Drives%& SET Available=%Available%
GOTO:EOF
:SyntaxECHO DrivUsed.bat, Version 1.00 for Windows XP and later
ECHO List used and available drive letters
ECHO.
ECHO Usage: DRIVUSED
ECHO.
ECHO Note: The list of drive letters in use is displayed on screen
ECHO and stored in an environment variable named "Drives".
ECHO The list of available drive letters is displayed on screen
ECHO and stored in an environment variable named "Available".
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
page last modified: 2025-10-11; loaded in 0.0077 seconds