Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
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

1 Answer 1

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

Your Answer

 
discard

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.