Fast Directory-to-HTML with Dir2HTML — A Practical Guide
What Dir2HTML is
Dir2HTML is a small utility that converts a filesystem directory (and its subdirectories) into a static HTML listing — useful for generating browsable indexes, static site file maps, or quick archives of a project’s file structure.
Key features
- Recursive directory traversal producing nested HTML lists or tables
- Customizable templates for controlling look and metadata shown (size, mtime, permissions)
- Filters and glob patterns to include/exclude files or file types
- Link generation that preserves relative paths for use on static sites or local file shares
- Lightweight and scriptable so it can be integrated into build scripts or CI pipelines
Typical usage (example workflow)
- Choose the root directory to publish (e.g., ./public or ./dist).
- Configure options: recursion depth, show hidden files, sort order (name/size/date), template path.
- Run Dir2HTML to produce an index.html (or multiple index files for subdirectories).
- Inspect and optionally tweak the template/CSS.
- Deploy the generated HTML alongside your static site or copy into a file share.
Common options to set
- –recursive / -r: include subdirectories
- –template PATH: use a custom HTML template
- –exclude PATTERN: skip files matching pattern
- –sort [name|size|date]: control listing order
- –show-size / –show-mtime: toggle extra columns
Tips for customization
- Use a template with placeholders for file name, relative URL, size, and modification time.
- Add CSS to make long filenames wrap and to visually collapse deep directory trees.
- Generate per-directory index.html files so links work on GitHub Pages or simple web servers.
- Preprocess filenames (e.g., replace underscores, add human-readable sizes) via a small wrapper script.
When to use Dir2HTML
- Publishing a simple, static file index without running a full CMS.
- Creating downloadable archives or project documentation snapshots.
- Building lightweight file browsers for intranets or static hosting.
(Date: February 5, 2026)
Leave a Reply