How to get integer of free disk space in Batch file?

前端 未结 4 1292
死守一世寂寞
死守一世寂寞 2020-12-11 04:32

I\'m trying to get integer of free disk space in Batch file. This is a my (very) simple code.

@echo off
wmic logicaldisk get freespace >> freespace.log         


        
4条回答
  •  长情又很酷
    2020-12-11 05:24

    Use below code. Try replacing the caption text with deviceid if it shows ? or blank.

    @echo off
    setlocal
    set drive=C
    set free=?
    rem Note: WMIC will output unicode text
    wmic logicaldisk where (caption = "%drive%:") get freespace>"%temp%\free.tmp"
    for /f %%A in ('type "%temp%\free.tmp"') do (set free=%%A)
    echo Free space: %free% bytes
    rem if exist "%temp%\free.tmp" del "%temp%\free.tmp"
    

提交回复
热议问题