Get size of a directory in 'MB' using batch file

后端 未结 4 1510

I want to get the size of directory say C:\\Temp in MB using batch file. I don\'t need sizes of child directories or files, but the size of directo

4条回答
  •  一个人的身影
    2020-11-27 08:39

    if you need exact values, go for another option. But if you need a rough value only (cut, not rounded, not 1024 as divisor but 1000 only):

    @echo off
    for /f "tokens=2 delims=," %%a in ('dir *^|findstr /e "Bytes"') do (
      for /f "delims= " %%i in ("%%a") do set size=%%i
    )
    echo size in Bytes: %size%
    echo that's about %size:~0,-4% KB
    echo or about %size:~0,-8% MB
    echo or about %size:~0,-12% GB
    

    Advantage: this is string manipulation only, no math included, so it even works outside 32bit Integer (which would be limited to sizes up to about 2GB).

提交回复
热议问题