(normally) - in two flavors. Used only to prioritize high-traffic pages for dev work, iff JS and tracker enabled. The former/defunct training site's id: ga('create', 'UA-52578333-1', 'auto'). The book site's id, now used for all: ga('create', 'UA-52579036-1', 'auto'). JS is also used if enabled for thumbspage galleries, Top buttons, TOCs, etc. Jun-2019: tell Google Analytics to anonymize IP address on receipt for privacy. More: https://developers.google.com/analytics/devguides/collection/analyticsjs/. Oct-2022: install a GA4 tag (i.e., script) alongside the prior UA tag. UA tags will stop collecting data in 2023. It's okay to use both until the cutover (and Google advises doing so), but the UA tag will be pointless after that and should be removed. This handles genhtml-insert clients; others get tags by running insert-analytics.py in package-publishing scripts. Also per Google: "In Google Analytics 4, IP anonymization is not necessary since IP addresses are not logged or stored". Let's hope so... --> treesize - File/Folder Sizes

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.

Overview

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.

Resources

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

Code and docs:

Examples:

Download

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

This program was last changed: June 2017. It was patched Jan-2025 for Python string-escape deprecations.

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 a related script that reports the number of items in each folder instead of space used, see folderitems.py. For more code examples, see the programs page.



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