Thursday, 15 March 2012

windows - Batch file displaying Fragmentation - Formatting output -



windows - Batch file displaying Fragmentation - Formatting output -

defrag c: /a /v > %temp%\defrag.txt /f "delims=" %%a in ('findstr /c:"total fragmented space" "%temp%\defrag.txt" ') set "fragmentation=%%a" echo %fragmentation%

this code works fine echos out spaces in file. here output:

--------------------------------------------------------------------- total c fragmentation: total fragmented space = 3%

is there way rid of spaces? have tried beingness more precise on search adding way until = sign no luck.

i appreciate help , give thanks time!

you can utilize spaces delimiter , retrieve separated elements

for /f "tokens=1-8" %%a in ( 'findstr /c:"total fragmented space" "%temp%\defrag.txt" ' ) set "fragmentation=%%a %%b %%c %%d %%e %%f %%g %%h"

or can straight utilize equal sign delimiter, value , later output need

for /f "tokens=2 delims==" %%a in ( 'findstr /c:"total fragmented space" "%temp%\defrag.txt" ' ) set "fragmentation=%%a" echo total c fragmentation: total fragmented space =%fragmentation%

and in of 2 cases, temporary file can avoided for command can run command , retrieve output

for /f "tokens=2 delims==" %%a in ( 'defrag c: /a /v ^| findstr /c:"total fragmented space" ' ) set "fragmentation=%%a"

windows batch-file

No comments:

Post a Comment