Duplique o sinal %
indicando as variáveis de controle de loop: %a
to %%a
, %b
to %%b
e assim por diante:
@ECHO OFF
SETLOCAL enableextensions
(for /f "tokens=1-3" %%a in ('
WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"
') do (
echo wsh.echo "%%b" ^& " free=" ^& FormatNumber^(cdbl^(%%a^)/1024/1024/1024, 2^)^& " GB"^& " size=" ^& FormatNumber^(cdbl^(%%c^)/1024/1024/1024, 2^)^& " GB" > "%temp%\tmp.vbs"
if not "%%c"=="" (
echo(
cscript //nologo "%temp%\tmp.vbs"
del "%temp%\tmp.vbs"
)
)
) > E:\monitoring_scripts\log\Disk_status.txt
ou, com menos gravações de disco na pasta %temp%
e com a única chamada cscript
:
@ECHO OFF
SETLOCAL enableextensions
(for /f "tokens=1-3" %%a in ('
WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"
') do (
if not "%%c"=="" (
echo wsh.echo vbNewLine ^& "%%b" ^& " free=" ^& FormatNumber^(cdbl^(%%a^)/1024/1024/1024, 2^)^& " GB"^& " size=" ^& FormatNumber^(cdbl^(%%c^)/1024/1024/1024, 2^)^& " GB"
)
)
) > "%temp%\tmp.vbs"
cscript //nologo "%temp%\tmp.vbs" > E:\monitoring_scripts\log\Disk_status.txt
del "%temp%\tmp.vbs"
Recursos (leitura adicional): Um índice A-Z da linha de comando do Windows CMD