User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
No directory selected
Leave empty to include all files
Paths matching this pattern are skipped entirely
0 = root only
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

About

Representing a file system hierarchy as a structured JavaScript object is a foundational task in build tools, documentation generators, static site scaffolding, and asset management pipelines. Manual construction of these trees is error-prone and scales poorly beyond a few dozen entries. This tool uses the browser's File System Access API to recursively traverse a selected directory and produce a faithful nested object matching the output format of the popular directory-tree npm package (~100k weekly downloads). Extension filtering accepts any valid RegExp pattern such as /\.(js|ts|html)$/, and path exclusion removes entire subtrees matching a second regex. Depth limiting caps traversal at level d, leaving deeper directory sizes as undefined to avoid misleading partial sums. The tool approximates file sizes from File.size bytes where available. Limitations: browsers do not expose Unix file mode, mtime, or symlink targets, so attribute options are constrained to what the Web API provides. The webkitdirectory fallback reconstructs the tree from flat relative paths and cannot detect empty directories.

directory-tree folder-structure json-tree file-system javascript-object directory-to-json file-tree-generator

Formulas

The directory tree is constructed via recursive depth-first traversal. For each directory entry at depth d, the algorithm checks against the depth limit and exclusion pattern before descending.

traverse(dir, d) โ†’
{
SKIP if d > maxDepthSKIP if excludeRegex.test(path)recurse children otherwise

File inclusion is determined by the extensions filter applied to each entry name:

include = extRegex.test(name) โˆจ extRegex = NULL

Directory size aggregation sums all child sizes bottom-up. If any child has undefined size (depth-limited), the parent size propagates as undefined:

size(dir) =
{
undefined if any child size is undefinednโˆ‘i=0 size(childi) otherwise

Where dir is the current directory handle, d is current depth level, maxDepth is the user-configured limit (defaults to โˆž), extRegex is the compiled extensions pattern, and n is the count of children in the directory.

Reference Data

AttributeTypeFilesDirectoriesDescription
namestringBase name of the entry
pathstringRelative path from root
typestring"file" or "directory"
sizenumber|undefinedBytes. undefined if depth-limited
extensionstringFile extension including dot (e.g. .jpg)
childrenArrayNested entries array
normalizePathbooleanOptionConvert \\ to /
depthnumberOptionMax traversal depth. 0 = root only
extensionsRegExpOptionInclude only matching file extensions
excludeRegExpOptionExclude paths matching pattern
Common Extension Patterns
Web files/\.(html|css|js|ts|jsx|tsx)$/
Images/\.(jpg|jpeg|png|gif|svg|webp|ico)$/
Documents/\.(pdf|doc|docx|txt|md|csv)$/
Audio/\.(mp3|wav|ogg|flac|aac)$/
Video/\.(mp4|avi|mkv|mov|webm)$/
Archives/\.(zip|tar|gz|rar|7z)$/
Data/\.(json|xml|yaml|yml|toml)$/
Source code/\.(py|rb|java|go|rs|c|cpp|h)$/
Fonts/\.(woff|woff2|ttf|otf|eot)$/
All text/\.(txt|md|log|csv|tsv)$/

Frequently Asked Questions

When a depth limit is set, directories at the boundary are not traversed. Their true size cannot be computed without reading all descendants. Rather than reporting a misleading partial sum, the tool sets size to undefined. Any parent directory containing a depth-limited child also inherits undefined size, since aggregation requires complete data. This matches the behavior of the directory-tree npm package.
Yes. The filter field accepts any valid JavaScript regular expression without delimiters. For example, entering \.(js|ts)$ will match files ending in .js or .ts. The pattern is compiled inside a try-catch block; invalid regex triggers an error toast rather than crashing the tool. Remember to escape the dot with a backslash since . in regex matches any character.
When using the modern File System Access API (showDirectoryPicker), yes. Empty directories appear as objects with an empty children array. However, with the webkitdirectory fallback (used in Firefox and older browsers), the browser only reports files, not empty directories. The tree is reconstructed from file paths, so directories with no matching files are invisible.
The exclude regex is tested against the full relative path of each entry (both files and directories). If a directory matches, the entire subtree is skipped. The extensions filter is applied only to files and only after exclusion. A file must pass both filters: its path must not match the exclude pattern, and its extension must match the extensions pattern (if one is set).
The File System Access API provides file size through the File object's size property, which reports the byte count at the time of access. This value is accurate for static files. However, unlike Node.js fs.stat, the browser cannot report block-level allocation, sparse file sizes, or sizes of files modified after the handle was obtained. For most use cases the difference is negligible.
Browsers do not expose symbolic links, FIFOs, sockets, or device files through either the File System Access API or the webkitdirectory input. These entries are silently omitted from the tree, consistent with the directory-tree npm package behavior which also ignores device, FIFO, and socket files.