From 5336b1acef52185a0fc558590aa5ae762e52c2ce Mon Sep 17 00:00:00 2001 From: Eirikr Hinngart <151315375+Oichkatzelesfrettschen@users.noreply.github.com> Date: Fri, 30 May 2025 08:45:32 -0700 Subject: [PATCH] Add file tree reporting script --- tools/file_tree_report.py | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 tools/file_tree_report.py diff --git a/tools/file_tree_report.py b/tools/file_tree_report.py new file mode 100755 index 000000000..ff9e92954 --- /dev/null +++ b/tools/file_tree_report.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +"""Generate a report of the repository file tree with file types.""" + +from __future__ import annotations + +import argparse +import os +from typing import Iterable, Tuple + + +def scan_tree(start: str) -> Iterable[Tuple[str, str]]: + """Yield each filesystem entry path and a human-readable type.""" + for root, dirs, files in os.walk(start): + for name in dirs: + path = os.path.join(root, name) + yield path, "directory" + for name in files: + path = os.path.join(root, name) + if os.path.islink(path): + yield path, "symlink" + else: + yield path, "file" + + +def main() -> None: + """Parse command line arguments and print the file tree report.""" + parser = argparse.ArgumentParser( + description="Generate a file tree report with file types" + ) + parser.add_argument( + "start", + nargs="?", + default=".", + help="directory to start scanning (default: current directory)", + ) + args = parser.parse_args() + + for path, ftype in scan_tree(args.start): + print(f"{path}\t{ftype}") + + +if __name__ == "__main__": + main()