1.

Solve : EOL in for loop.?

Answer»

Ok i got a question. Here i have some code to show the first 9 drives on a computer. but it's long and i think it could be shortened:
Code: [Select]for /f "tokens=2-10 delims=:\ " %%A in ('fsutil fsinfo drives') do (
if .%%A NEQ . fsutil fsinfo drivetype %%A:
if .%%B NEQ . fsutil fsinfo drivetype %%B:
if .%%C NEQ . fsutil fsinfo drivetype %%C:
if .%%D NEQ . fsutil fsinfo drivetype %%D:
if .%%E NEQ . fsutil fsinfo drivetype %%E:
if .%%F NEQ . fsutil fsinfo drivetype %%F:
if .%%G NEQ . fsutil fsinfo drivetype %%G:
if .%%H NEQ . fsutil fsinfo drivetype %%H:
if .%%I NEQ . fsutil fsinfo drivetype %%I:)
If the output of the 'fsutil fsinfo drives' command could be split onto several lines we could use this code instead:

Code: [Select]for /f "delims=:\ " %%A in ('fsutil fsinfo drives') do fsutil fsinfo drivetype %%A:
So I've tried using the "eol=" option but this doesn't seem to work, any ideas?

cheers FBThe first output line from fsutil has a different format than the rest of the lines:

Code: [Select]@echo off
for /f "tokens=1-2" %%f in ('fsutil fsinfo drives') do (
fsutil fsinfo drivetype %%g
)
for /f %%f in ('fsutil fsinfo drives ^| find /i /v "drives"') do (
fsutil fsinfo drivetype %%f
)

You can decide if this is any better. But while you're deciding, why not use diskpart:

Code: [Select]@echo off
for /f "skip=9 tokens=3" %%i in ('echo list volume ^| diskpart') do (
echo %%i:\
)

Use the pipe to send output of diskpart to the find command if you're looking for something specific.

Good luck. QUOTE from: Sidewinder on January 06, 2009, 02:49:29 PM

The first output line from fsutil has a different format than the rest of the lines:

fsutil fsinfo drives only has one line of output, that is my issue exactly.

Quote from: Sidewinder on January 06, 2009, 02:49:29 PM
Code: [Select]@echo off
for /f "skip=9 tokens=3" %%i in ('echo list volume ^| diskpart') do (
echo %%i:\
)

Use the pipe to send output of diskpart to the find command if you're looking for something specific.

Good luck.

The diskpart doesn't quite do it either, the number of tokens is unpredictable.

Is there anything else to suggest

cheers FBQuote
fsutil fsinfo drives only has one line of output, that is my issue exactly.

I stand by the response. Did you try the code?

Code: [Select]@echo off
for /f "tokens=1-2" %%f in ('fsutil fsinfo drives') do (
fsutil fsinfo drivetype %%g
)
for /f %%f in ('fsutil fsinfo drives ^| find /i /v "drives"') do (
fsutil fsinfo drivetype %%f
)

Output from this machine:
Quote
C:\ - Fixed Drive
D:\ - Fixed Drive
E:\ - Fixed Drive
F:\ - Fixed Drive
G:\ - Fixed Drive
H:\ - CD-ROM Drive
I:\ - Removable Drive

Diskpart could be used to filter all the removable drives, or the partitions or even the CD/DVD drives. Depending what you're looking for, the token issue should not be a problem.



Code: [Select]@echo off

for /f "tokens=1-2" %%f in ('fsutil fsinfo drives') do (
fsutil fsinfo drivetype %%g
)
for /f %%f in ('fsutil fsinfo drives ^| find /i /v "drives"') do (
fsutil fsinfo drivetype %%f
)Output: Quote
C:\ - Fixed Drive

Out of five drives it lists one.

I don't want to filter the results I just want to Drive letter and type.

cheers FBQuote
Out of five drives it lists one.

Could be something unique to XP that was "fixed" in Vista. This is little SNIPPET does an end run AROUND the for logic, but has it all over a series of if STATEMENTS by processing as many or as few drives that exist on the system.

Code: [Select]@echo off
set num=1
:loop
set /a num+=1
for /f "tokens=%num%" %%i in ('fsutil fsinfo drives') do (
if .%%i==. goto getout
fsutil fsinfo drivetype %%i
goto loop
)
)
:getout


Code: [Select]for /f "tokens=3 skip=8" %%A in ('echo list volume ^| diskpart') do (fsutil fsinfo drivetype %%A:)
Got it, thanks for the help.

FB


Discussion

No Comment Found