Get Folder Size from Windows Command Line

前端 未结 17 2428
滥情空心
滥情空心 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:34

    The following script can be used to fetch and accumulate the size of each file under a given folder.
    The folder path %folder% can be given as an argument to this script (%1).
    Ultimately, the results is held in the parameter %filesize%

    @echo off
    SET count=1
    SET foldersize=0
    FOR /f "tokens=*" %%F IN ('dir /s/b %folder%') DO (call :calcAccSize "%%F")
    echo %filesize%
    GOTO :eof
    
    :calcAccSize
     REM echo %count%:%1
     REM set /a count+=1
     set /a foldersize+=%~z1
     GOTO :eof
    

    Note: The method calcAccSize can also print the content of the folder (commented in the example above)

提交回复
热议问题