(view source code of freedriveletter.bat as plain text)
@ECHO OFF
:: FREEDRIVELETTER
:: Small batch file to list all unused drive letters (works ONLY on 2000/XP/2003)
:: by Rob van der Woude
:: from an idea and minor fixes by Jacopo Lazzari
:: http://www.robvanderwoude.com
:: Not for Windows 95/98/ME/NT4
IF NOT "%OS%"=="Windows_NT" EXIT
VER | FIND "Windows NT" >NUL && EXIT
SETLOCAL ENABLEDELAYEDEXPANSION
SET ALLDRIVES=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 BUSYDRV=
SET FREEDRV=
:: List drive letters for physical drives
FOR %%A IN (%ALLDRIVES%) DO (
FOR /F %%B IN ('MOUNTVOL %%A: /L ^|FINDSTR /C:"\\"') DO (
SET BUSYDRV=!BUSYDRV!,%%A:
)
)
:: List drive letters for network drives
FOR /F "tokens=2" %%A IN ('NET USE ^|FINDSTR /R /C:" [A-Z]: "') DO SET BUSYDRV=!BUSYDRV!,%%A
:: Remove leading comma
SET BUSYDRV=%BUSYDRV:~1%
:: Remove backslashes
SET BUSYDRV=%BUSYDRV:\=%
:: Check which drive letters aren't used and list them as free drive letters
FOR %%A IN (%ALLDRIVES%) DO (
ECHO.%BUSYDRV% | FIND "%%A:" >NUL
IF ERRORLEVEL 1 SET FREEDRV=!FREEDRV!,%%A:
)
:: Remove leading comma
SET FREEDRV=%FREEDRV:~1%
:: Display result
SET BUSYDRV
FOR %%A IN (%BUSYDRV%) DO ECHO %%A BUSY
SET FREEDRV
FOR %%A IN (%FREEDRV%) DO ECHO %%A FREE
ENDLOCAL
page last modified: 2024-04-16; loaded in 0.0060 seconds