Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
if defined filePath echo %COMPUTERNAME% %username% yes >> \\server\%computername%.txt
share|improve this question
Does 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 like cmd.exe on steroids) – Darth Android Jan 2 '13 at 20:52
'Xcept it's legal! – RookieTEC9 Oct 22 '15 at 11:38

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.

share|improve this answer

if exist %%i: not always work. So you can also check your drives with this way :

(dir %%i:>NUL) && (
  echo Drive [%%i]: exist
) || (
  echo Drive [%%i]: NOT exist

Hope this helps

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.