How to get the only the total files size from folders dir in windows commandline [self answered]
-
Welcome to Superuser! Googling shows many examples. What have you tried? Do you get any error?– Reddy LutonadioCommented Sep 3, 2021 at 8:57
-
1Ty, I have a self answer, but couldn't use the check box and do it concurrently because I have no reputation– RobinCommented Sep 3, 2021 at 9:04
-
… and now you have some ;) You might still have to wait a while before it will let you mark the answer as accepted. Welcome to Super User!– TetsujinCommented Sep 3, 2021 at 9:09
2 Answers
I tested this on Powershell:
gci Downloads | measure Length -s
To see the result in MB:
(gci Downloads | measure Length -s).Sum /1MB
More details on the available options, how to include the subdirectories etc. available here:
https://4sysops.com/archives/measure-object-computing-the-size-of-folders-and-files-in-powershell/
-
I've been too long out of the community... thanks @Mokubai for reminding me of the bare basics :-) Commented Sep 3, 2021 at 9:15
I have found elsewhere that
dir /a/s
lists all files and folders
But to tidy this up we can use findstr, the tail of the dir command is like
Total files listed:
nn File(s) n,nnn,nnn bytes
mm Dir(s) p,pppp,ppp bytes free
So
dir /a/s | findstr "Dir(s)"
shows the last line, which is the free bytes on the disk
Another search example
dir /a/s | findstr "Dir.File(s)"
findstr looks for each string separated by a space
So it also shows the file space used in each sub folder