Reputation: 161
i'm doing some maintenence script and want to get defragment status like this:
@echo off
setlocal EnableExtensions
defrag c: -a>%TEMP%\defrag_c_fixed.txt
for /f "skip=4 delims=,( tokens=4" %%a in (%TEMP%\defrag_c_fixed.txt) do set fragment=%%a
for /f "skip=5 tokens=*" %%a in (%TEMP%\defrag_c_fixed.txt) do set recommend=%%a
echo !fragment!
echo !recommend!
pause
I'm getting fragment status with spaces in the start of the numbers:
20% Fragmented
You should defragment this volume.
Press any key to continue . . .
How can i delete this from script?
Upvotes: 0
Views: 213
Reputation: 130919
You can use FOR /F to strip leading spaces. Using TOKENS=* will strip leadiing delimiters, and the default delimiters are space and tab.
for /f "tokens=*" %%A in ("!fragment!") do echo(%%A
Upvotes: 3