1

I'm calculating free disk space using

fsutil volume diskfree D: >> test.txt

But now since the output is something like that :

Nombre total d'octets libres              : 529557839872
Nombre total d'octets                     : 1000203087872
Nombre total d'octets libres disponibles  : 529557839872

I would like to convert into Mo or Go if possible

vincs2
  • 33
  • 3
  • 2
    batch math is limited to 32bit Integer. Nowadays disk sizes exceed those limits, so you have to use other methods. [some ideas](http://stackoverflow.com/q/36301198/2152082). – Stephan Apr 06 '16 at 09:52

1 Answers1

0

Try something like this to convert disk sizes :

@echo off
NET FILE 1>NUL 2>NUL
if %errorlevel% == 0 goto elevated
REM build vbs to invoke UAC
(
    echo Set UAC = CreateObject^("Shell.Application"^)
    echo UAC.ShellExecute %0, "", "", "runas", 1 
)> "%temp%\getadmin.vbs"

ECHO ******
ECHO Invoking UAC for Privilege Escalation
ECHO ******

"%temp%\getadmin.vbs" >nul
exit /B

:elevated
    del "%temp%\getadmin.vbs" 2>nul    
    CD "%~dp0"
(
    for /f "tokens=2 delims=:" %%a in ('fsutil volume diskfree D:') do Call:GetSize %%a
)>Disk_Free.txt
start "" Disk_Free.txt
pause
Exit /b
::*************************************************************************
:GetSize
(
echo wscript.echo FormatSize("%~1"^)
echo '*******************************************************************
echo 'Function to format a number into typical size scales
echo Function FormatSize(iSize^)
echo    aLabel = Array("bytes", "KB", "MB", "GB", "TB"^)
echo    For i = 0 to 4
echo        If iSize ^> 1024 Then
echo            iSize = iSize / 1024
echo        Else
echo            Exit For
echo        End If
echo    Next
echo    FormatSize = Round(iSize,2^) ^& " " ^& aLabel(i^)
echo End Function
echo '*******************************************************************
)>%tmp%\Size.vbs
Cscript /NoLogo %tmp%\Size.vbs
Del %tmp%\Size.vbs
Exit /b
Hackoo
  • 18,337
  • 3
  • 40
  • 70