Solved: Batch file to give me directory disk sizes

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

vince43

Thread Starter
Joined
Sep 20, 2008
Messages
2
I'm trying to create a batch file that will give me the size of a list of directories. I'm not interested in the sizes of folders within the list of directories just the top level directory sizes, if that makes sense.
For example, I want to be able to work out the size of the user profiles on a machine, so if there were 5 users, I want to work out the size of those 5 top level profile directories.
 
Joined
Aug 7, 2007
Messages
9,028
So what you need is the last line of the Dir /s output, the Total Files Listed: info.
The following uses a subroutine, so you can call it repeatedly from within a batch file:
Code:
@Echo Off
Call :_TotalSize "C:\Documents and Settings\TheOutcaste\"
Call :_TotalSize "C:\Documents and Settings\User2\"
Call :_TotalSize "%appdata%"
Goto :EOF
:_TotalSize
Set _size=0
For /F "tokens=3 delims= " %%I In ('Dir "%~1" /a-d /S ^|Find /I "file(s)"') Do Set _size=%%I
Echo The %1 tree is %_size% Bytes total
Goto :EOF
For a quick standalone, use just:
Code:
@Echo Off
Set _size=0
For /F "tokens=3 delims= " %%I In ('Dir "%~1" /a-d /S ^|Find /I "file(s)"') Do Set _size=%%I
Echo The %1 tree is %_size% Bytes total
use filename "pathtocheck" -- pathtocheck must be in quotes, even if you are using a variable like %userprofile% or %appdata%

Does the same as DIRUSE, but you don't have to download it

HTH

Jerry
 
Joined
Aug 7, 2007
Messages
9,028
You're Welcome!

If your issue has been resolved you (and ONLY you) can mark this thread Solved by using the Mark Solved button at the Top Right of this thread (above the first post) :)



Jerry
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top