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