Visualize any folder on your machine as an interactive tree in the browser.
This project provides:
- a small CLI (
dir-to-graph) that walks a directory and writes adata.jsonfile - an HTML/D3 viewer (
index.html) that readsdata.jsonand renders a zoomable tree
The graph shows folders and files, with node size roughly proportional to size on disk.
The easiest way to use dir_to_graph on your own machine is to fork this repository and clone your fork locally.
-
On GitHub, go to: https://github.com/carobs9/dir_to_graph
-
Click Fork to create your own copy under your account.
-
Clone your fork:
git clone https://github.com/<your-username>/dir_to_graph.git cd dir_to_graph
-
(Optional but recommended) Create and activate a virtual environment, then install dependencies:
python -m venv .venv source .venv/bin/activate # on macOS/Linux # .venv\Scripts\activate # on Windows pip install -r requirements.txt
Python 3.10+ and a few Python libraries:
pip install -r requirements.txtrequirements.txt currently includes:
- networkx
- numpy
From the repository root (inside your forked/checked-out dir_to_graph):
cd dir_to_graph
python main.py /path/to/your/directoryWhat this does:
- runs the CLI banner and help text
- walks
/path/to/your/directory(recursively) - builds a tree representation with per‑node metadata
- writes a D3‑friendly JSON file named
data.jsoninto the output directory (default = dir_to_graph directory)
You should see a message like:
[INFO] Wrote directory structure as a JSON: /…/dir_to_graph/data.json
Next steps:
1. python -m http.server 8000
2. Open http://localhost:8000/index.html in your browser
Then follow those steps to start a local web server and open the visualization.
To end the local web server, simply type the following command in the terminal:
Ctrl + C
You can now close the local host in your browser.
The CLI entrypoint is implemented in dir_to_graph/cli.py and exposed via main.py.
Usage:
python main.py [PATH] [-o OUTPUT_DIR] [-i NAME ...] [--max-seconds SECONDS]Arguments:
PATH(positional, optional): directory to analyze. Defaults to.(current directory).-o, --output-dir: where to writedata.json. By default it is written intoPATH.-i, --ignore: directory name to ignore (can be passed multiple times). Defaults include:.git,.venv,bin,__pycache__,.ipynb_checkpoints
--max-seconds: approximate time budget (in seconds) for computing folder sizes.- default:
15.0 - after the budget is used up, the tool stops computing precise sizes and continues building the tree, using
None(rendered as size 0) for remaining nodes. - set to
0to disable the limit and compute all sizes.
- default:
The viewer lives in index.html. It assumes:
index.htmlanddata.jsonare in the same directory- a simple HTTP server is serving that directory (e.g.
python -m http.server 8000)
At a high level:
index.htmlfetchesdata.json:const JSON_PATH = "data.json"; const raw = await fetch(JSON_PATH).then(r => r.json());
- It converts the JSON into a D3 hierarchy (
d3.hierarchy(raw)) and appliesd3.treeto compute positions. - Nodes are rendered as circles; folders are one color, files another.
- Labels use the short
name(file or folder name), while tooltips show both name and full path, plus formatted size. - Clicking a folder expands/collapses its children; hovering shows size information.
The JSON schema roughly matches what networkx.readwrite.json_graph.tree_data produces, with extra attributes:
- each node has
id: full absolute path (unique)name: basename shown in the UItype:"folder"or"file"size_bytes: integer bytes, orNoneif not computed within the time budgetchildren: list of child nodes (folders/files)
You can also use the functionality programmatically from Python:
from dir_to_graph import build_tree_json, write_tree_json
tree = build_tree_json("/path/to/dir", max_seconds=10)
print(tree["name"], tree["children"][0]["name"])
out_path = write_tree_json("/path/to/dir", output_dir=".", filename="data.json")
print("wrote", out_path)This is useful if you want to embed the directory graph in another application or run it from a notebook.
- Very large directories can still take noticeable time, especially if
--max-seconds 0is used. - Size calculation skips files that cannot be read (
OSErroris ignored). - The project is experimental; APIs and output format may change.
Contributions and ideas for new visualizations are welcome.
- I am developing an LLM to be able to ask interactively regarding the organization of the folders and files, and potentially their contents.
