There’s this nice tool called WinDirStat which lets you scan a directory and view files in a rectangular tree map. It looks like this:

The size of each block is related to the file size, and blocks are grouped by directory and coloured distinctly according to the top level directory. I’d like to create a map like this in Mathematica. First I get some file names in the tree of my Mathematica installation and calculate their sizes:

`fassoc = FileSystemMap[FileSize, File[$ InstallationDirectory], Infinity, IncludeDirectories -> False]; `

Level `Infinity`

ensures it traverses the whole tree. I could also add `1`

to ensure the association is flattened, but I want the nesting so I can assign total sizes per directory.

I can find the total size which I’ll need to use to scale the rectangles:

`QuantityMagnitude[Total[Cases[fassoc, Quantity[_, _], Infinity]], "Bytes"] `

My idea is to recursively apply this total. In theory I could use this to do something like this with a tree graph and weight the vertices by size, but I want to convert this into a map of rectangles like in WinDirStat. While the colour is obvious – each level 1 association and all its descendants gets a `RandomColor[]`

– I’m not sure how I should go about positioning the rectangles in a `Graphics`

. Any ideas?