Free space in a CMD shell

后端 未结 9 1834
北海茫月
北海茫月 2020-12-02 10:04

Is there a way to get the amount of free diskspace of a disk or a folder in a CMD without having to install some thirdparty applications?

I have a CMD that copies a

9条回答
  •  遥遥无期
    2020-12-02 10:47

    I make a variation to generate this out from script:

    volume C: - 49 GB total space / 29512314880 byte(s) free

    I use diskpart to get this information.

    @echo off
    setlocal enableextensions enabledelayedexpansion
    set chkfile=drivechk.tmp
    if "%1" == "" goto :usage
    set drive=%1
    set drive=%drive:\=%
    set drive=%drive::=%
    dir %drive%:>nul 2>%chkfile%
    for %%? in (%chkfile%) do (
      set chksize=%%~z?
    )
    if %chksize% neq 0 (
      more %chkfile%
      del %chkfile%
      goto :eof
    )
    del %chkfile%
    echo list volume | diskpart | find /I " %drive% " >%chkfile%
    for /f "tokens=6" %%a in ('type %chkfile%' ) do (
        set dsksz=%%a
    )
    for /f "tokens=7" %%a in ('type %chkfile%' ) do (
        set dskunit=%%a
    )
    del %chkfile%
    for /f "tokens=3" %%a in ('dir %drive%:\') do (
      set bytesfree=%%a
    )
    set bytesfree=%bytesfree:,=%
    echo volume %drive%: - %dsksz% %dskunit% total space / %bytesfree% byte(s) free
    endlocal
    
    goto :eof
    :usage
      echo.
      echo   usage: freedisk ^ (eg.: freedisk c)
    

提交回复
热议问题