Project Files
get_structure.py
###```python
import os
import sys
def generate_project_structure(root_path, output_file="project_structure.md"):
"""
Generate a markdown file with visually indented folder tree structure.
Output is written to the same directory as the script.
"""
try:
root_path = os.path.abspath(root_path)
output_path = os.path.join(root_path, output_file)
md_content = "# Project Structure\n\n"
# Stack for tracking current path depth
stack = []
visited = set()
# Walk through directory tree with indentation
for root, dirs, files in os.walk(root_path):
# Relative path from root
rel_path = os.path.relpath(root, root_path)
rel_parts = rel_path.split(os.sep)
# Build the path with indentation
indent = " " * (len(rel_parts) - 1) # One level per directory
# Skip empty paths
if not rel_parts:
rel_path = ""
# Only process directories that are not hidden (optional)
dirs[:] = [d for d in dirs if not d.startswith('.')]
# Add folder header
if rel_path == "":
md_content += f"## {rel_path}\n"
else:
md_content += f"{indent}## {rel_path}\n"
# Add files in this directory
for file in sorted(files):
file_ext = os.path.splitext(file)[1]
file_name = file
md_content += f"{indent} - {file_name} ({file_ext})\n"
# Write to file
with open(output_path, 'w', encoding='utf-8') as f:
f.write(md_content)
print(f"✅ Successfully generated {output_file} in {root_path}")
return True
except Exception as e:
print(f"❌ Error: {e}")
return False
# Main execution
if __name__ == "__main__":
current_dir = os.getcwd()
generate_project_structure(current_dir)
###```