Skip to content

Instantly share code, notes, and snippets.

@Lenochxd
Created January 13, 2025 21:33
Show Gist options
  • Save Lenochxd/015d675b4ba02c4d95aba77febc9d539 to your computer and use it in GitHub Desktop.
Save Lenochxd/015d675b4ba02c4d95aba77febc9d539 to your computer and use it in GitHub Desktop.
import pyperclip
import os
IGNORE = ['lib', 'dist', 'build', 'venv', '__pycache__', '.logs', '.git', '.github']
EXTENSIONS_ONLY_DIRS = ['img', 'icons']
output = ''
def print_and_log(t):
global output
print(t)
output += t + '\n'
printed_extensions = {}
def print_dir_tree(start_path, prefix="", is_ext=False):
entries = os.listdir(start_path)
entries.sort()
total_entries = len(entries)
for i, entry in enumerate(entries):
if entry in IGNORE:
continue
path = os.path.join(start_path, entry)
connector = "└── " if i == total_entries - 1 else "├── "
if is_ext:
ext = os.path.splitext(entry)[1]
dir = os.path.dirname(path).split('/')[-1]
if ext in printed_extensions.get(dir, []):
continue
print_and_log(prefix + connector + "... "+ext)
printed_extensions.setdefault(dir, []).append(ext)
else:
print_and_log(prefix + connector + entry)
if os.path.isdir(path):
new_prefix = prefix + (" " if i == total_entries - 1 else "│ ")
if entry in EXTENSIONS_ONLY_DIRS:
print_dir_tree(path, new_prefix, is_ext=True)
else:
print_dir_tree(path, new_prefix)
if __name__ == "__main__":
project_dir = input("Enter the project directory path (default is current directory): ").strip() or "."
print(f"\nDirectory tree for: {os.path.abspath(project_dir)}\n")
print(project_dir)
print_dir_tree(project_dir)
pyperclip.copy(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment