How to make a batch file to search all drives?
6,773
There's no variable that simply carries all mapped letters.
if you're running as admin,
fsutil fsinfo drives
returns all such drives- an example bit of code:
FOR /F "usebackq tokens=1" %%a IN (`MOUNTVOL ^| FIND ":\"`) DO (FOR /F "usebackq tokens=3" %%b IN (`FSUTIL FSINFO DRIVETYPE %%a`) DO (IF /I "%%b" EQU "Removable" ECHO %%a ))
(play with the outputs)
... if not workable, you're gonna have to blast through them all, ie:
for %%i in (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 @if exist %%i: @echo %%i:
(probably should omit the expected optical drive/memory-card drive letters).
VBS-scripting, or Powershell is ideal for this sort of thing.
Related videos on Youtube
Author by
Joe Witkowski
Updated on September 18, 2022Comments
-
Joe Witkowski over 1 year
How can I get this batch file to read all physical and mapped drives? It works fine with C: but will not read any other drive.
@echo off set filePath= for /R c:\ /d %%a in (*) do if exist "%%a\FileName" set filePath=%%a& goto continue :continue if defined filePath echo %COMPUTERNAME% %username% yes >> \\server\%computername%.txt
-
user1984103 over 11 yearsDoes it have to be a
.bat
batch file, or can it be a.ps
PowerShell file? (You list Windows 7 as the OS, and Powershell comes standard on Windows 7. It's likecmd.exe
on steroids) -
Roke over 8 years'Xcept it's legal!
-
-
Jiab77 over 7 yearsMaybe my post should be moved as a comment of the answer of @solemnity