How can I check the size of a folder from the Windows command line?
I want to use the Windows command line to calculate the size of all the files in a folder and subfolder. I would normally do this by right-clicking on the folder and clicking "Properties" but I want to be able to do it on the command line.
Which command can I use?
Solution 1:
You will want to use dir /a/s
so that it includes every file, including system and hidden files. This will give you the total size you desire.
Solution 2:
You can use PowerShell!
$totalsize = [long]0
Get-ChildItem -File -Recurse -Force -ErrorAction SilentlyContinue | % {$totalsize += $_.Length}
$totalsize
This recurses through the entire current directory (ignoring directories that can't be entered) and sums up the sizes of each file. Then it prints the total size in bytes.
Compacted one-liner:
$totalsize=[long]0;gci -File -r -fo -ea Silent|%{$totalsize+=$_.Length};$totalsize
On my machine, this seems slightly faster than a dir /s /a
, since it doesn't print each object's information to the screen.
To run it from a normal command prompt:
powershell -command "$totalsize=[long]0;gci -File -r -fo -ea Silent|%{$totalsize+=$_.Length};$totalsize"