treesize — Get Sizes of all Files and Folders in a Tree

This page hosts treesize, a Python command-line script that you can use to isolate large files and folders taking up space on your devices. This script also demos recursion and basic file interfaces in Python.


This modest Python 3.X program generates a report giving the total space taken by each folder and file in a directory tree, grouped by type and ordered by size. This includes all the subfolders nested in the tree; each folder's size is computed from its contents recursively. After a run, search the report for "[Directories]" and "[Files]" to find your largest items.

This script's main goal is to help locate candidates for removal when reclaiming disk space; navigating with file explorer GUIs tends to be tedious (or unusable) in this role. Its report file also provides a snapshot of the contents of your folders or drives. While there are tools to do similar work on some platforms, treesize is a portable option that works everywhere that Python does.


See the main script's docstring and other items below for usage details.

Code and docs:



Use the following to fetch treesize, or view its unzipped content.

This program was last changed: June 2017.

Recent upgrades: treesize includes a minor update to skip symlinks on platforms that support them, so the size tally isn't inflated artificially. Symlinks are rare on Windows, but not on Mac OS or Linux. See the script's docstring for details. This script has also now been shown to handle non-ASCII filenames properly on all Python/platform combinations tested (without the perils of its CGI-script comrades here and here).

For more code examples, see the programs page.

[Home page] Books Code Blog Python Author Train Find ©M.Lutz