Get Folder Size from Windows Command Line

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

    This code is tested. You can check it again.

    @ECHO OFF
    CLS
    SETLOCAL
    ::Get a number of lines contain "File(s)" to a mytmp file in TEMP location.
    DIR /S /-C | FIND "bytes" | FIND /V "free" | FIND /C "File(s)" >%TEMP%\mytmp
    SET /P nline=<%TEMP%\mytmp
    SET nline=[%nline%]
    ::-------------------------------------
    DIR /S /-C | FIND "bytes" | FIND /V "free" | FIND /N "File(s)" | FIND "%nline%" >%TEMP%\mytmp1
    SET /P mainline=<%TEMP%\mytmp1
    CALL SET size=%mainline:~29,15%
    ECHO %size%
    ENDLOCAL
    PAUSE
    

提交回复
热议问题