{"id":49065028,"url":"https://github.com/abbas-jafri-aj/dir_tree_builder","last_synced_at":"2026-04-20T04:17:14.588Z","repository":{"id":323477860,"uuid":"1093406127","full_name":"abbas-jafri-aj/dir_tree_builder","owner":"abbas-jafri-aj","description":"dir_tree_builder is a Python module and CLI tool for recursively building a directory tree and outputting it as JSON.","archived":false,"fork":false,"pushed_at":"2025-11-10T10:29:56.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-10T12:16:38.645Z","etag":null,"topics":["convert-directory-tree-to-json","directory-tree-traversal","json"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abbas-jafri-aj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-10T10:28:07.000Z","updated_at":"2025-11-10T10:33:42.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/abbas-jafri-aj/dir_tree_builder","commit_stats":null,"previous_names":["abbas-jafri-aj/dir_tree_builder"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/abbas-jafri-aj/dir_tree_builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abbas-jafri-aj%2Fdir_tree_builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abbas-jafri-aj%2Fdir_tree_builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abbas-jafri-aj%2Fdir_tree_builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abbas-jafri-aj%2Fdir_tree_builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abbas-jafri-aj","download_url":"https://codeload.github.com/abbas-jafri-aj/dir_tree_builder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abbas-jafri-aj%2Fdir_tree_builder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32032453,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convert-directory-tree-to-json","directory-tree-traversal","json"],"created_at":"2026-04-20T04:17:13.518Z","updated_at":"2026-04-20T04:17:14.576Z","avatar_url":"https://github.com/abbas-jafri-aj.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dir_tree_builder\n\ndir_tree_builder is a Python module and CLI tool for recursively building a directory tree and outputting it as JSON. It supports file metadata, nested directories, empty directories, and optional human-readable file sizes and timestamps.\n\n---\n\n## Features\n\n- Recursively traverse directories to any depth (or unlimited with -1)\n- Represent files with metadata (size and last modification time)\n- Represent directories as nested dictionaries\n- Include empty directories explicitly\n- Optionally format sizes and timestamps in human-readable form\n- Handles permission errors gracefully\n- Safe to import as a module; logging is optional and configurable\n- Python 3.8+ compatible\n- No external dependencies, uses only standard library\n\n---\n\n## Installation\n\nClone or download the repository. No pip installation is required:\n\n```\ngit clone https://github.com/abbas-jafri-aj/dir_tree_builder.git\ncd dir_tree_builder\n```\n\n---\n\n## Usage\n\n### As a script\n\n```\npython dir_tree_builder.py /home/user/project [--depth N] [--human-readable] [--logfile FILE]\n```\n\n- `path` : Directory or file to inspect\n- `--depth N` : Maximum recursion depth (default: 3, -1 for unlimited)\n- `--human-readable` : Display human-readable sizes and timestamps\n- `--logfile FILE` : Optional log file path\n\nExample:\n\n```\n$ python dir_tree_builder.py /usr/local --depth 2 --human-readable\n09:54:30 [INFO] Building directory tree for /usr/local (depth=2, human_readable=True)\n{\n    \"bin\": {\n        \"start-systemd\": {\n            \"size\": \"3.7 KB\",\n            \"modified_time\": \"2023-05-02 18:50\"\n        },\n        \"update.sh\": {\n            \"size\": \"5.1 KB\",\n            \"modified_time\": \"2023-05-02 18:50\"\n        },\n        \"upgrade.sh\": {\n            \"size\": \"5.1 KB\",\n            \"modified_time\": \"2023-05-02 18:50\"\n        },\n        \"wslsystemctl\": {\n            \"size\": \"284.6 KB\",\n            \"modified_time\": \"2023-05-02 18:50\"\n        }\n    },\n    \"etc\": {},\n    \"games\": {},\n    \"include\": {},\n    \"lib\": {},\n    \"lib64\": {\n        \"bpf\": {}\n    },\n    \"libexec\": {},\n    \"sbin\": {},\n    \"share\": {\n        \"applications\": {},\n        \"info\": {},\n        \"man\": {}\n    },\n    \"src\": {}\n}\n```\n\n### As a module\n\nImport and use in your Python code:\n\n```\nfrom dir_tree_builder import get_dir_tree, dir_tree_to_json\n\ntree = get_dir_tree(\"/home/user/project\", depth=2, human_readable=True)\nprint(dir_tree_to_json(tree))\n```\n\nOptional logging can be passed:\n\n```\nimport logging\nfrom dir_tree_builder import get_dir_tree, setup_logger\n\nlogger = setup_logger(\"tree.log\")\ntree = get_dir_tree(\"/home/user/project\", depth=2, human_readable=True, logger=logger)\n```\n\n---\n\n## Logging\n\n- By default, the module does not output logs when imported.\n- Use the optional `logger` parameter in `get_dir_tree` or `get_file_info` to enable logging.\n- When running as a script, use `--logfile` to write logs to a file.\n\n---\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabbas-jafri-aj%2Fdir_tree_builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabbas-jafri-aj%2Fdir_tree_builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabbas-jafri-aj%2Fdir_tree_builder/lists"}