【问题标题】:FSUTIL in GB space leftFSUTIL 剩余 GB 空间
【发布时间】:2017-10-24 14:36:32
【问题描述】:

我有一个执行以下操作的批处理文件。

echo Server 1 C:\>>output.txt
fsutil volume diskfree \\IPISHERE\d$>>output.txt
echo ---------------------------------------------------------- >>output.txt

然后将数据显示为

Total # of free bytes        : 71942455296
Total # of bytes             : 131623546880
Total # of avail free bytes  : 71942455296

请有人帮忙,以便我将其转换为 GB 吗?

【问题讨论】:

  • SET /A 命令只能对 32 位整数进行算术运算。最大 +- 值为 2,147,483,647。
  • 如果您不需要精度,您可以删除 6 个 LS 数字,或者删除 6 个 LS 数字并向上取整。然后根据需要在适当的位置插入小数点。

标签: batch-file command fsutil


【解决方案1】:
@echo off
setlocal EnableDelayedExpansion

for /F "tokens=1* delims=:" %%a in ('fsutil volume diskfree C:') do for %%c in (%%b) do (
   set "D=%%c"
   set /A "D1=!D:~0,-8!,D2=1!D:~-8,-4!-10000,D3=1!D:~-4!-10000"
   for /L %%f in (1,1,3) do ( rem Number of divisions: KB, MB, GB
      set /A "F=0,C=0"
      for /L %%i in (1,1,3) do ( rem Quads in the number of bytes: 3*4 = 12 digits
         set /A "F+=^!^!D%%i"
         if !F! neq 0 set /A "D=C*10000+D%%i,D%%i=D/1024,C=D%%1024"
      )
   )
   set /A "C=C*10000/1024+10000
   echo %%a: !D3!.!C:~1,2! GB
)

输出示例:

C:\Users\Antonio\Documents\Test> fsutil volume diskfree C:
Número total de bytes libres            : 406596222976
Número total de bytes                   : 474821423104
Número total de bytes libres disponibles: 406596222976

C:\Users\Antonio\Documents\Test> test.bat
Número total de bytes libres            : 378.67 GB
Número total de bytes                   : 442.21 GB
Número total de bytes libres disponibles: 378.67 GB

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-17
    • 2013-02-22
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多