Get Folder Size from Windows Command Line

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

    Oneliner:

    powershell -command "$fso = new-object -com Scripting.FileSystemObject; gci -Directory | select @{l='Size'; e={$fso.GetFolder($_.FullName).Size}},FullName | sort Size -Descending | ft @{l='Size [MB]'; e={'{0:N2}    ' -f ($_.Size / 1MB)}},FullName"
    

    Same but Powershell only:

    $fso = new-object -com Scripting.FileSystemObject
    gci -Directory `
      | select @{l='Size'; e={$fso.GetFolder($_.FullName).Size}},FullName `
      | sort Size -Descending `
      | ft @{l='Size [MB]'; e={'{0:N2}    ' -f ($_.Size / 1MB)}},FullName
    

    This should produce the following result:

    Size [MB]  FullName
    ---------  --------
    580,08     C:\my\Tools\mongo
    434,65     C:\my\Tools\Cmder
    421,64     C:\my\Tools\mingw64
    247,10     C:\my\Tools\dotnet-rc4
    218,12     C:\my\Tools\ResharperCLT
    200,44     C:\my\Tools\git
    156,07     C:\my\Tools\dotnet
    140,67     C:\my\Tools\vscode
    97,33      C:\my\Tools\apache-jmeter-3.1
    54,39      C:\my\Tools\mongoadmin
    47,89      C:\my\Tools\Python27
    35,22      C:\my\Tools\robomongo
    

提交回复
热议问题