Question: I use Mathematica10 in my Win7 and I want to estimate the amount of disk space occupied by each dirs.

I try the code(the code was copied from [How do I find the amount of free space on disk?](https://mathematica.stackexchange.com/questions/16804/how-do-i-find-the-amount-of-free-space-on-disk/16830#16830), actually I don't know how it works at all):

```
dirsofD = FileNames["*", "D:\\"]

```

and

```
sizeoddirsofD = 
ToExpression@
StringJoin[
 ReadList["!dir " <> #, Word, RecordLists -> True, 
   WordSeparators -> {" ", ","}][[-2, 3 ;; -2]]] & /@ dirsofD

```

However, the code above only count the files directive under certain dir while the files under subdirs of given dir are missed, which means the search depth is only one. How could I get the whole size of all files of certain dir?

Answer: 
There is also a function in the `Internal`` context (for now) that does that

```
Internal`DirectoryByteCount[$InstallationDirectory]

(* 6794576686 *)

```

which is in agreement with what my OS reports for that directory

[![enter image description here](https://i.stack.imgur.com/tshdt.png)](https://i.stack.imgur.com/tshdt.png)
An estimate can be obtained without resorting to the underlying OS.

`FileByteCount` can be used to obtain the size of a file and `FileNames` can list files to any depth so combining these in to a function:

```
recursiveFolderSize[folder_String] := 
 Plus @@ Quiet[
   FileByteCount /@ FileNames["*", folder, Infinity] /. $Failed -> 0, 
   FileByteCount::fdir]

```

`FileByteCount` gives a message and returns `$Failed` for directories so the function handles these cases.

Also note that directories themselves take up disk space so the total returned will be an underestimate.