Get Folder Size from Windows Command Line

前端 未结 17 2353
滥情空心
滥情空心 2020-11-28 18:52

Is it possible in Windows to get a folder\'s size from the command line without using any 3rd party tool?

I want the same result as you would get when right clicking

17条回答
  •  粉色の甜心
    2020-11-28 19:25

    I guess this would only work if the directory is fairly static and its contents don't change between the execution of the two dir commands. Maybe a way to combine this into one command to avoid that, but this worked for my purpose (I didn't want the full listing; just the summary).

    GetDirSummary.bat Script:

    @echo off
    rem  get total number of lines from dir output
    FOR /F "delims=" %%i IN ('dir /S %1 ^| find "asdfasdfasdf" /C /V') DO set lineCount=%%i
    rem  dir summary is always last 3 lines; calculate starting line of summary info
    set /a summaryStart="lineCount-3"
    rem  now output just the last 3 lines
    dir /S %1 | more +%summaryStart%
    

    Usage:

    GetDirSummary.bat c:\temp

    Output:

     Total Files Listed:
              22 File(s)         63,600 bytes
               8 Dir(s)  104,350,330,880 bytes free
    

提交回复
热议问题