本帖最后由 523066680 于 2019-1-5 20:27 编辑
回复 1# aries215
你想要第一列和最后一列是吗?- @echo off
- SetLocal EnableDelayedExpansion
- for /f "tokens=1,3" %%i in ('fsutil volume diskfree c:') do (
- set "a=%%i"
- set "b=%%j"
- echo !a! - !b!
- )
复制代码 蛋疼一点:- @echo off
- SetLocal EnableDelayedExpansion
- :: 常量初始化
- set sharp=####################
-
- :get_total_size
- for /f "tokens=3" %%i in ('fsutil volume diskfree c:') do (set total=%%i&goto :get_free_size)
- :get_free_size
- for /f "tokens=3" %%i in ('fsutil volume diskfree c: ^|more +1') do (set free=%%i&goto :count)
-
- :count
- call :bignum_minus %total% %free% delta
- echo %total% %free% 已用空间 %delta%
- exit /b
-
- ::大数减法
- :bignum_minus
- setlocal
- set num_a=%1
- set num_b=%2
- call :length %num_a% len_a
- call :length %num_b% len_b
- set /a max = len_a
- if %len_b% gtr %len_a% (set /a max=len_b, len_b=len_a&set num_a=%num_b%&set num_b=%num_a%)
-
- set /a minus = 0
- for /l %%n in ( 1, 1, %max% ) do (
- if %%n leq %len_b% (
- set /a dt = !num_a:~-%%n,1! - !num_b:~-%%n,1! - minus
- ) else (
- set /a dt = !num_a:~-%%n,1! - minus
- )
- if !dt! lss 0 (
- set /a buff[%%n] = dt + 10, minus=1
- ) else (
- set /a buff[%%n] = dt, minus=0
- )
- )
-
- set delta=#
- for /l %%a in (%max%, -1, 1) do set delta=!delta:#0=#!!buff[%%a]!
- endlocal &set %3=%delta:#=%
- goto :eof
-
- ::字符串长度计算
- :length %str% %vname%
- setlocal
- set test=%~1_%sharp%
- set test=!test:~0,20!
- set test=%test:*_=%
- set /a len=20-(%test:#=1+%1)
- endlocal &set %2=%len%
- goto :eof
复制代码 如果你要我转换成 KB MB GB ,对不起,我不会批处理,我是论坛消遣区负责灌水的。 |