41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
import os
|
|
import json
|
|
import time
|
|
|
|
root_dir = os.path.dirname(os.path.abspath(__file__))
|
|
manifest_path = os.path.join(root_dir, "workspace_manifest.json")
|
|
summary_path = os.path.join(root_dir, "workspace_tree_summary.txt")
|
|
|
|
folders = []
|
|
counts = {"dirs": 0, "files": 0, "by_ext": {}}
|
|
|
|
print(f"Scanning {root_dir}...")
|
|
start_time = time.time()
|
|
|
|
with open(summary_path, "w", encoding="utf-8") as sum_f:
|
|
for dirpath, dirnames, filenames in os.walk(root_dir):
|
|
# Exclude git directories and system temp
|
|
dirnames[:] = [d for d in dirnames if d not in ('.git', '__pycache__')]
|
|
rel_dir = os.path.relpath(dirpath, root_dir)
|
|
counts["dirs"] += 1
|
|
|
|
sum_f.write(f"[{rel_dir}] (dirs: {len(dirnames)}, files: {len(filenames)})\n")
|
|
|
|
folders.append({
|
|
"path": rel_dir if rel_dir != "." else "",
|
|
"subdirs": list(dirnames),
|
|
"file_count": len(filenames),
|
|
})
|
|
|
|
for f in filenames:
|
|
counts["files"] += 1
|
|
ext = os.path.splitext(f)[1].lower()
|
|
counts["by_ext"][ext] = counts["by_ext"].get(ext, 0) + 1
|
|
|
|
elapsed = time.time() - start_time
|
|
print(f"Scan finished in {elapsed:.1f}s. Total dirs: {counts['dirs']}, files: {counts['files']}.")
|
|
|
|
with open(manifest_path, "w", encoding="utf-8") as f:
|
|
json.dump({"root": os.path.basename(root_dir), "stats": counts, "directories": folders}, f, indent=2)
|
|
|
|
print(f"Saved manifest to {manifest_path} and {summary_path}") |