|
- @echo off &setlocal enabledelayedexpansion
- set "GB=1073741824"
- ::已知1GB可以存放1073741824字节
- for /f "skip=1 delims=" %%i in ('wmic LogicalDisk where "Caption='C:'" get DeviceID^,FreeSpace^,Size') do (
- for /f "tokens=1-3" %%j in ("%%i") do call :output %%j %%k %%l
- )
- goto :eof
- :output
- for /f "tokens=1-4" %%i in ('mshta vbscript:Execute("CreateObject(""Scripting.FileSystemObject"").GetStandardStream(1).Write(FormatNumber(%3/%GB%, 2) & "" "" & FormatNumber((%3-%2)/%GB%, 2) & "" "" & FormatNumber(%2/%GB%, 2) & "" "" & Round((%3-%2)*50/%3)):Close"^)') do (
- set "size= %%i"
- set "used= %%j"
- set "free= %%k"
- set /a "nUsed=%%l, nFree=50-%%l"
- )
- echo,
- set c=%1
- echo %c:~0,1% 分区 总空间大小: %size:~-10% GB
- echo %c:~0,1% 分区 已使用空间: %used:~-10% GB
- echo %c:~0,1% 分区 剩余空间: %free:~-10% GB
- pause>nul
- goto :eof
复制代码 |
|