Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Does anyone know of a free command-line tool or script that calculates the size of a directory including all subdirectories?

It needs to be compatible with Windows 7, work with hard links and junctions and gracefully deal with access denied to some subfolder (i.e. continues in such a case).

I could not find anything and am thinking of writing my own tool.


I am looking for something to analyze (many) roaming user profiles stored on a file server. The perfect tool would make it easy to find the largest profile directories or those with the most files.

share|improve this question
add comment

6 Answers 6

up vote 3 down vote accepted

Du by Sysinternals might be what you're looking for. It's free from Microsoft, and it's basically a rudimentary version of the *ix du. It deals with junctions and denied permissions by reporting the file doesn't exist.


Du v1.34 - report directory disk usage
Copyright (C) 2005-2009 Mark Russinovich
Sysinternals - www.sysinternals.com

usage: du [[-v] [-l <levels>] | [-n]] [-q] <directory>
   -l     Specify subdirectory depth of information (default is all levels)
   -n     Do not recurse.
   -q     Quiet (no banner).
   -u     Count only unique file occurences.
   -v     Show size (in KB) of intermediate directories.

c:\sysinternals>du c:\sysinternals

Du v1.34 - report directory disk usage
Copyright (C) 2005-2009 Mark Russinovich
Sysinternals - www.sysinternals.com

Files:        101
Directories:  0
Size:         32,798,999 bytes
Size on disk: 32,798,999 bytes
share|improve this answer
This is exactly what I was looking for. Thank you! –  Helge Klein Mar 30 '11 at 7:45
add comment

Using robocopy with /l will do it, ignoring things that you don't have access to, and /B will even try in backuo mode, which might get you access you otherwise wouldn't have.

/L :: List only - don't copy, timestamp or delete any files.

/XJ :: eXclude Junction points. (normally included by default).

Is there anything specific you meant by "gracefully deal with access denied to some subfolder" ?

/Edit - now that you've asked essentially an entirely new question, I will flood you with other answers:

Do why do you need it running on Windows 7? Run it on the server (s).

How do you expect to see this used? Crystal Reports can use a filesystem as a reporting source, and you could group by size in one report, and by number of files in another. Does it need to have history? You could use something like RRDTool to run diruse on every folder in the parent directory or directories where you keep your homedirs. And then you have nice pretty webpages with nice pretty graphs.

For interactive use, I love WinDirStat, but some people like TreeSize Pro.

How does this tie into your need to have this be redistributable? Are you trying to build and sell a management product for other IT admins? If it's just for you and your staff, that's not "redistributing."

share|improve this answer
Added more specific explanation of what I meant with "gracefully ..." –  Helge Klein Mar 29 '11 at 19:58
In that case, robocopy will work just fine. –  mfinni Mar 29 '11 at 20:03
Interesting solution. I tried "robocopy DirToAnalyze c:\dummy /l /xj /e /nfl /ndl /njh /r:0" and it worked well. Adding /b for backup access to all files (as admin) works well, too. It also lists the numbers of files and directories, which may be good to know. One downside, though: Parsing the output and comparing many different directories is difficult. –  Helge Klein Mar 29 '11 at 20:07
Robocopy has saved my hide any number of times. –  mfinni Mar 29 '11 at 20:10
Parsing output and comparing many directories wasn't one of your requirements, and should probably be a separate question with what your needs are for that. –  mfinni Mar 29 '11 at 20:13
show 1 more comment

An all-default install of Cygwin (a POSIX emulation layer for Windows) includes the du utility from the GNU core utilities collection, and it is fully hard-link and junction-point aware. I believe Cygwin (and thus du) treats junction points as soft-links.

share|improve this answer
I need something I can redistribute, and cannot tell potential users to install Cygwin first, I am afraid. –  Helge Klein Mar 29 '11 at 19:55
@Helge Klein: You know your users/customers better than I do, of course. But just so you are aware, Cygwin is distributable under the GPL. –  Steven Monday Mar 29 '11 at 20:08
And you can redistribute it with just the DLL and the executable, you certainly don't need the whole package. @Helge - If you have other requirements or planned usage, it can be helpful to describe that in your question. –  mfinni Mar 29 '11 at 20:11
add comment

You really should look at http://foldersize.codeplex.com/releases?ReleaseName=FolderSize.Win32. it rocks! Easy graphical way to see who is chewing up what space.

enter image description here

share|improve this answer
add comment

Have you looked into the Microsoft tool diruse? It's a command line tool that does exactly what you're looking for. It's part of the server tools for Windows 2000 & 2003, but is still available for download: Microsoft Diruse TechNet article.

The only thing I'm not sure about is how it handles hard-links and junction points. It might be worth experimenting with.

Example from the TechNet article:

diruse /* /m \\shared\data 

 Size (mb)  Files  Directory
       248.60   3739  SUB-TOTAL: \\SHARED\DATA\Admin
        31.27     36  SUB-TOTAL: \\SHARED\DATA\Common
      1448.14  23654  SUB-TOTAL: \\SHARED\DATA\ConsultServ
       107.64    750  SUB-TOTAL: \\SHARED\DATA\CorpServ
      1053.28   6145  SUB-TOTAL: \\SHARED\DATA\Design
       147.11    258  SUB-TOTAL: \\SHARED\DATA\Engrg
        70.56    745  SUB-TOTAL: \\SHARED\DATA\Finance
        18.78   1188  SUB-TOTAL: \\SHARED\DATA\Hardware
        12.18     50  SUB-TOTAL: \\SHARED\DATA\HR
         2.22     23  SUB-TOTAL: \\SHARED\DATA\InfoTech
         5.44     46  SUB-TOTAL: \\SHARED\DATA\Legal
        18.53     56  SUB-TOTAL: \\SHARED\DATA\ProdDev
       470.43   2016  SUB-TOTAL: \\SHARED\DATA\ProdMktg
       107.92   1445  SUB-TOTAL: \\SHARED\DATA\Research
        31.10     43  SUB-TOTAL: \\SHARED\DATA\Sales
         9.98     14  SUB-TOTAL: \\SHARED\DATA\TechSupp
       114.82   1269  SUB-TOTAL: \\SHARED\DATA\Training
      3898.00  41477  TOTAL
share|improve this answer
Diruse never comes back when analyzing a V2 user profile. It was my first choice, too, but unfortunately is unusable for me. –  Helge Klein Mar 30 '11 at 7:25
add comment

It may be a little lowbrow for Server Fault, but Tree Size Free (http://www.jam-software.com/treesize_free/) will do that quite well, especially if you're just trying for a one time use. The Professional version has a lot of nice features that I use for ongoing maintenance.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.