Skip to main content

🧭 Emoji + Metadata + Tree Layout

Here's a complete Python script that generates a visually appealing tree structure of your project folder using emoji icons and file metadata. The output is formatted as a Bash-style code block perfect for embedding in Docusaurus.

Emojis from Microsoft

Full Expressive Python Script​

https://copilot.microsoft.com/shares/B7pvjR59PwjbFEnyQNiEJ

generate_tree_md.py
import os
import datetime

# πŸ”§ Feature toggles
INCLUDE_EMOJI = True
INCLUDE_METADATA = False
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = False

# πŸ—’οΈ Manual file comments (extend as needed)
MANUAL_COMMENTS = {
"WebBrowser.js": "Main browser component",
"WebBrowser.module.css": "Browser styles",
"BrowserExamples.js": "Example components (optional)",
"README.md": "Project overview",
"config.json": "Configuration settings"
}

# 🎭 Emoji mapping by file extension
def emoji_for_file(file_name):
ext = os.path.splitext(file_name)[1].lower()
return {
'.js': 'πŸ“œ',
'.ts': 'πŸ“˜',
'.css': '🎨',
'.scss': '🧡',
'.html': '🌐',
'.py': '🐍',
'.md': 'πŸ“',
'.json': 'πŸ”§',
'.jpg': 'πŸ–ΌοΈ',
'.png': 'πŸ–ΌοΈ',
'.txt': 'πŸ“„',
'.test.js': 'πŸ§ͺ',
'.lock': 'πŸ”’',
}.get(ext, 'πŸ“„')

# πŸ“‚ Emoji by folder purpose
def emoji_for_folder(folder_name):
mapping = {
'test': 'πŸ§ͺ',
'tests': 'πŸ§ͺ',
'components': '🧩',
'config': 'βš™οΈ',
'public': '🌐',
'docs': 'πŸ“š',
'scripts': 'πŸ“œ',
'assets': '🎨',
'utils': '🧰',
}
for key, icon in mapping.items():
if key.lower() in folder_name.lower():
return icon
return 'πŸ“‚'

# πŸ“Š Generate metadata comment
def get_file_metadata_comment(file_path):
stats = os.stat(file_path)
size_kb = stats.st_size / 1024
mtime = datetime.datetime.fromtimestamp(stats.st_mtime)
ext = os.path.splitext(file_path)[1].lower().lstrip('.').upper() or "Unknown"
return f"{ext} file, {size_kb:.1f} KB, modified {mtime.strftime('%Y-%m-%d %H:%M')}"

# 🌳 Recursive folder walker
def map_folder_structure(root_path, indent=""):
lines = []
items = sorted(os.listdir(root_path))
for idx, item in enumerate(items):
item_path = os.path.join(root_path, item)
is_last = idx == len(items) - 1
prefix = "└── " if is_last else "β”œβ”€β”€ "
line_prefix = indent + prefix
# Folder line
if os.path.isdir(item_path):
folder_emoji = emoji_for_folder(item) if SMART_FOLDER_LABELS and INCLUDE_EMOJI else ('πŸ“' if INCLUDE_EMOJI else '')
spacing = ' ' if INCLUDE_EMOJI else ''
line = f"{line_prefix}{folder_emoji}{spacing}{item}/"
lines.append(line)
new_indent = indent + (" " if is_last else "β”‚ ")
lines.extend(map_folder_structure(item_path, new_indent))
# File line
else:
file_emoji = emoji_for_file(item) if INCLUDE_EMOJI else ''
spacing = ' ' if INCLUDE_EMOJI else ''
comments = []

if INCLUDE_COMMENTS and item in MANUAL_COMMENTS:
comments.append(MANUAL_COMMENTS[item])
if INCLUDE_METADATA:
comments.append(get_file_metadata_comment(item_path))

comment_str = f" # {' | '.join(comments)}" if comments else ''
line = f"{line_prefix}{file_emoji}{spacing}{item}{comment_str}"
lines.append(line)

return lines

# πŸ§ͺ Wrap it all for Markdown embedding
def generate_docusaurus_bash_block(root_path):
root_name = os.path.basename(os.path.abspath(root_path))

if SMART_FOLDER_LABELS and INCLUDE_EMOJI:
top_icon = emoji_for_folder(root_name)
elif INCLUDE_EMOJI:
top_icon = 'πŸ“‚'
else:
top_icon = ''

spacing = ' ' if INCLUDE_EMOJI else ''
lines = [f"{top_icon}{spacing}{root_name}/"]
lines.extend(map_folder_structure(root_path))
return "```bash\n" + "\n".join(lines) + "\n```"

# ▢️ Example usage
output = generate_docusaurus_bash_block("src/components")
print(output)

with open("project-structure.md", "w", encoding="utf-8") as f:
f.write("## πŸ“‚ Project Structure\n\n")
f.write(output)

πŸ“‚ Project Structure​

# πŸ”§ Feature toggles
INCLUDE_EMOJI = True
INCLUDE_METADATA = True
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = True
🧩 components/
β”œβ”€β”€ πŸ“œ BashTerminal.js # JS file, 5.3 KB, modified 2025-07-22 08:59
β”œβ”€β”€ 🎨 BashTerminal.module.css # CSS file, 3.1 KB, modified 2025-07-22 08:59
β”œβ”€β”€ πŸ“œ BrowserExamples.js # Example components (optional) | JS file, 3.5 KB, modified 2025-07-22 08:59
β”œβ”€β”€ πŸ“‚ BrowserWindow/
β”‚ β”œβ”€β”€ πŸ“œ index.js # JS file, 1.1 KB, modified 2025-07-22 08:59
β”‚ └── 🎨 styles.module.css # CSS file, 1.6 KB, modified 2025-07-22 08:59
β”œβ”€β”€ πŸ“‚ HomepageFeatures/
β”‚ β”œβ”€β”€ πŸ“œ index.js # JS file, 1.7 KB, modified 2025-07-22 08:59
β”‚ └── 🎨 styles.module.css # CSS file, 0.1 KB, modified 2025-07-22 08:59
β”œβ”€β”€ πŸ“œ TerminalExamples.js # JS file, 1.4 KB, modified 2025-07-22 08:59
β”œβ”€β”€ πŸ“œ WebBrowser.js # Main browser component | JS file, 7.1 KB, modified 2025-07-22 08:59
β”œβ”€β”€ 🎨 WebBrowser.module.css # Browser styles | CSS file, 7.0 KB, modified 2025-07-22 08:59
└── πŸ“œ YouTubeEmbed.js # JS file, 1.1 KB, modified 2025-07-22 08:59
# πŸ”§ Feature toggles
INCLUDE_EMOJI = True
INCLUDE_METADATA = False
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = True
🧩 components/
β”œβ”€β”€ πŸ“œ BashTerminal.js
β”œβ”€β”€ 🎨 BashTerminal.module.css
β”œβ”€β”€ πŸ“œ BrowserExamples.js # Example components (optional)
β”œβ”€β”€ πŸ“‚ BrowserWindow/
β”‚ β”œβ”€β”€ πŸ“œ index.js
β”‚ └── 🎨 styles.module.css
β”œβ”€β”€ πŸ“‚ HomepageFeatures/
β”‚ β”œβ”€β”€ πŸ“œ index.js
β”‚ └── 🎨 styles.module.css
β”œβ”€β”€ πŸ“œ TerminalExamples.js
β”œβ”€β”€ πŸ“œ WebBrowser.js # Main browser component
β”œβ”€β”€ 🎨 WebBrowser.module.css # Browser styles
└── πŸ“œ YouTubeEmbed.js
# πŸ”§ Feature toggles
INCLUDE_EMOJI = True
INCLUDE_METADATA = False
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = False
πŸ“‚ components/
β”œβ”€β”€ πŸ“œ BashTerminal.js
β”œβ”€β”€ 🎨 BashTerminal.module.css
β”œβ”€β”€ πŸ“œ BrowserExamples.js # Example components (optional)
β”œβ”€β”€ πŸ“‚ BrowserWindow/
β”‚ β”œβ”€β”€ πŸ“œ index.js
β”‚ └── 🎨 styles.module.css
β”œβ”€β”€ πŸ“‚ HomepageFeatures/
β”‚ β”œβ”€β”€ πŸ“œ index.js
β”‚ └── 🎨 styles.module.css
β”œβ”€β”€ πŸ“œ TerminalExamples.js
β”œβ”€β”€ πŸ“œ WebBrowser.js # Main browser component
β”œβ”€β”€ 🎨 WebBrowser.module.css # Browser styles
└── πŸ“œ YouTubeEmbed.js
# πŸ”§ Feature toggles
INCLUDE_EMOJI = False
INCLUDE_METADATA = False
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = False
components/
β”œβ”€β”€ BashTerminal.js
β”œβ”€β”€ BashTerminal.module.css
β”œβ”€β”€ BrowserExamples.js # Example components (optional)
β”œβ”€β”€ BrowserWindow/
β”‚ β”œβ”€β”€ index.js
β”‚ └── styles.module.css
β”œβ”€β”€ HomepageFeatures/
β”‚ β”œβ”€β”€ index.js
β”‚ └── styles.module.css
β”œβ”€β”€ TerminalExamples.js
β”œβ”€β”€ WebBrowser.js # Main browser component
β”œβ”€β”€ WebBrowser.module.css # Browser styles
└── YouTubeEmbed.js