Get Folder Size from Windows Command Line

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

    Try:

    SET FOLDERSIZE=0
    FOR /F "tokens=3" %A IN ('DIR "C:\Program Files" /a /-c /s ^| FINDSTR /C:" bytes" ^| FINDSTR /V /C:" bytes free"') DO SET FOLDERSIZE=%A
    

    Change C:\Program Files to whatever folder you want and change %A to %%A if using in a batch file

    It returns the size of the whole folder, including subfolders and hidden and system files, and works with folders over 2GB

    It does write to the screen, so you'll have to use an interim file if you don't want that.

提交回复
热议问题