# How to find the cumulative size of a directory

Is there a switch for the dir command which lists the size of a directory as well?

Dir also displays the total number of files and directories listed, their cumulative size, and the free space (in bytes) remaining on the disk.

But it doesn't to specify how! Any help is appreciated.

I am not looking for batch scripts but just for one line command.

-

Try dir /s /a directory-name. You'll see a total byte count in the 2nd to last line. The /a flag tells it to include any system or hidden files in the count.

-
Won't work, args are incorrect. – Karan Oct 15 '12 at 4:51
Works for me on both Win7 x64 and WinXP. I don't know why you're having trouble. – Nicole Hamilton Oct 15 '12 at 5:04
It actually works for you with a space after the /a? Weird. Also, /as /ah will only include system and hidden files, not all files. /a by itself will include everything. – Karan Oct 15 '12 at 5:05
You bet. On both machines. Mind you, I think dir is totally clunky and don't use it myself but, yeah, it worked when I tried it (and retried it after you raised an objection.) Personally, I would do it more straightforwardly with my own ls command as ls -lw! directory where -l means long listing, -w means walk subdirs to calculate sizes and -! means list just the directory, not its contents, producing a single line of output with the result. But I understood the OP as asking how to do with only what comes from Microsoft and this seemed to do it – Nicole Hamilton Oct 15 '12 at 5:15
@Nicole: A-ha, now I've got what exactly you're doing wrong! 1) Please check that you don't have dirs named s and h. 2) Type dir /s /a h /a s DirName just like you mentioned. 3) Check the output very carefully. The 1st line should be "Volume in drive X is Y", the 2nd line "Volume Serial Number is Z", and most importantly, the 3rd line will be "File Not Found", while the 4th line of text will be "Directory of Drive:\Path\to\DirName" followed by the listing for DirName. That 3rd line is extremely important, please check if it's there. – Karan Oct 15 '12 at 16:51

If you are on Windows Vista or later, it will come with PowerShell. You can then run this command directly from the command line:

powershell -c "Get-ChildItem -Recurse 'path_to_dir' | Measure-Object -Property Length -Sum"


Sum will be the size in bytes.

You can download and install PowerShell for some earlier versions of Windows. Additionally, I strongly recommend switching to PowerShell or a POSIX shell. The Windows command line (cmd.exe) is only good for more basic operations; beyond that it can get horrifyingly complex. Especially if you want one-liners.

-
And this is why Microsoft will never be able to kill off Linux. du -sh /path. You, too, can have simplified commands if you follow Bob's advice by installing a POSIX shell like CYGWIN. – UtahJarhead Oct 16 '12 at 18:42

A great reference for dos/nt commands is http://ss64.com/; sometimes technet is better, but ss64 will also, at the bottom, list other related methods to accomplish similar deeds. ie: commands for particular results "DIRUSE" and sometimes even an equal Powershell command.

BTW - the gnuwin32 project has many of the core command utilities available from the nix world and usually there is one directly aimed at doing what needs doing... in this case the du command, where du -b will list the output size the same as dir /A /S and du -h makes it human readable. :)

Hope that helps.

-