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

This is what I have so far

@echo off
for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name format:value') do echo %%d

output is correct

@echo off
FORFILES /P C:\ /S /M *.* /C "cmd /c echo @path"

output is correct

@echo off
for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name format:value') do FORFILES /P %%d\ /S /M *.* /C "cmd /c echo @path"

output seems to report an invalid drive for each drive on the system but I can not get it to process the %%d as C:\ D:\ etc,

any suggestions

share|improve this question
Why use batch for Windows 8? Time to start PowerShelling, son! – HopelessN00b Mar 28 '14 at 1:12
I am just learning this stuff, one step at a time, DAD! – Donald Mar 28 '14 at 1:18
Well, you can learn with PowerShell just as well as batch... and you'll find Powershell much more useful and full-featured. For that matter, there's even a PowerShell ISE that can help you learn and punch up your scripts in ways you won' be able to do with batch and cmd. – HopelessN00b Mar 28 '14 at 1:29
but does power shell run on 32 / 64 bit OS and does it work on XP vista 7 and 8, right now I am trying to learn this and also meet a need I have that applies to multiple computers – Donald Mar 28 '14 at 1:31
Yup! – HopelessN00b Mar 28 '14 at 1:36
up vote 1 down vote accepted

WMIC produces unicode output, and FOR /F converts the output to ANSI improperly such that there is an extra carriage return (<CR>) at the end of each line of output.

So your drive becomes C:<CR>\ - the carriage return is messing up the command.

One way to eliminate the unwanted character is to add an extra FOR loop, which trims exactly one trailing <CR> from the end of a line, if it exists.

Also, unless Windows 8 is different than all earlier versions, WMIC requires a slash before the FORMAT option, as in /format:value

@echo off
for /f "tokens=2 delims==" %%A in (
  'wmic logicaldisk where "drivetype=3" get name /format:value'
) do for %%B in (%%A) do forfiles /p %%B\ /s /m *.* /c "cmd /c echo @path"
share|improve this answer
So if I am understanding this correctly, the first part generated the correct output except it had extra information in it that in a raw form was messing with the second part, you add that middle part extracting only what we needed from the first part ignoring the extra information, is my understanding correct ? – Donald Mar 28 '14 at 4:52
@Donald - Yes, you got it. If you are interested in seeing the extra char, you can do something like (for /f "delims=" %A in ('wmic ...') do @echo %A)>output.txt, and then examine the output using a hex editor. You will see every line terminated by <CR><CR><LF>, instead of the expected <CR><LF>. – dbenham Mar 28 '14 at 11:45
I came across a program called --can i say names here-- and it allows me to turn on something called show all characters, now I can see extra stuff like tabs returns and things like that, is this what your referring to. – Donald Mar 29 '14 at 6:02
@Donald - That would probably work, but it is not what I was referring to. A hex editor shows a two character hexadecimal representation of every byte in a file, even binary files. Try a web search for "hex editor". There are plenty of freeware hex editors available. – dbenham Mar 29 '14 at 10:52
how would a person redirect this command to a variable instead of a txt file – Donald Apr 27 '14 at 12:22

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.