0

I'd like the free space to be in GB, not MB. How could I change that?

for /f "tokens=3" %%a in ('dir c:\') do (
    set bytesfree=%%a
)
set bytesfree=%bytesfree:,=%
echo Free space on partition C: [%bytesfree%] B
endlocal && set bytesfree=%bytesfree%
nyiaq
  • 1

1 Answers1

1
  • For command line:
for /f usebackq^tokens^=4delims^=^>^< %i in (`wmic logicaldisk where Caption^="C:" get FreeSpace /format:xml^|find "VALUE"`)do for /f %G in ('start "" /b /min mshta "vbscript:Execute("createobject(""scripting.filesystemobject""^).GetStandardStream(1^).write(Round(%i/1073741824^)^):close")"^|more')do echo\Free space on partition C: [%G] GB
  • For bat/cmd file:
@echo off

for /f usebackq^tokens^=4delims^=^>^< %%i in (wmic logicaldisk where Caption^=&quot;C:&quot; get FreeSpace /format:xml^|find &quot;VALUE&quot;)do for /f %%G in (' start "" /b /min mshta "vbscript:Execute("createobject(""scripting.filesystemobject""^).GetStandardStream(1^).write(Round(%%i/1073741824^)^):close")"^|more ')do echo\Free space on partition C: [%%G] GB


  1. You have no option that makes the space available in MB or GB
  2. To get in MB or GB units, at some point you have to convert from unit bytes
  3. See set /a command can convert units but has 32 bit integer limit
  4. When converting, it is necessary to use or , in hybrid mode or in a "mixed" command line.
  5. It is possible to use a "mixed" line in hybrid mode or bat file, and as in the example above, it is possible to execute with mshat.exe to interpret and execute with vbs the desired conversion of bytes to GB:
Io-oI
  • 9,237