我正在使用以下批处理程序来获取系统驱动器详细信息。
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1" %%d in (
'wmic logicaldisk where drivetype^=3 get deviceid ^| find ":"') do (
for /f "skip=1 tokens=1,* delims=:" %%a in ('fsutil volume diskfree %%d') do (
Call :ConvertBytes %%b GB Gigs
Call :ConvertBytes %%b MB Megs
echo %%d - %%a: !Gigs! GB (^!Megs! MB^)
set s=%%d - %%a: !Gigs! GB (^!Megs! MB^)
echo %s% >>C:\myfile.txt
)
)
pause;
goto :eof
:ConvertBytes bytes unit ret
setlocal
if "%~2" EQU "KB" set val=/1024
if "%~2" EQU "MB" set val=/1024/1024
if "%~2" EQU "GB" set val=/1024/1024/1024
> %temp%\tmp.vbs echo wsh.echo FormatNumber(eval(%~1%val%),0)
for /f "delims=" %%a in (
'cscript //nologo %temp%\tmp.vbs'
) do endlocal & set %~3=%%a
del %temp%\tmp.vbs
此批次的输出将为:
C: - Total # of bytes : 98 GB (99,900 MB)
C: - Total # of avail free bytes : 32 GB (33,122 MB)
D: - Total # of bytes : 146 GB (150,000 MB)
D: - Total # of avail free bytes : 138 GB (141,728 MB)
E: - Total # of bytes : 222 GB (226,938 MB)
E: - Total # of avail free bytes : 208 GB (213,473 MB)
Press any key to continue . . .
这里我试图将批处理的输出写入文本文件。因为我在for循环中给出了echo %s% >>C:\myfile.txt
语句。但它在文本文件中打印ECHO is off.
。
我曾尝试在暂停前给出echo语句;命令,这样做只有输出的最后一行(E: - Total # of avail free bytes : 208 GB (213,473 MB)
)写入文本文件。
如何打印文本文件中的所有6行。
答案 0 :(得分:1)
替换此echo %s% >>C:\myfile.txt
用这个
>>C:\myfile.txt echo !s!