File size: 1,762 Bytes
774ec97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# generate_tree.py
import os
from pathlib import Path

def should_exclude(path_name):
    """Define qué carpetas y archivos excluir"""
    exclude_patterns = {
        'venv', '__pycache__', '.git', 'node_modules', 
        '.vscode', '.idea', 'dist', 'build', '.pytest_cache',
        '*.pyc', '*.pyo', '*.egg-info'
    }
    
    for pattern in exclude_patterns:
        if pattern in str(path_name):
            return True
    return False

def generate_tree(directory, prefix='', max_depth=4, current_depth=0):
    """Genera un árbol de directorios limpio"""
    if current_depth > max_depth:
        return []
    
    lines = []
    items = sorted(Path(directory).iterdir(), key=lambda x: (not x.is_dir(), x.name))
    
    # Filtrar items excluidos
    items = [item for item in items if not should_exclude(item.name)]
    
    for index, item in enumerate(items):
        is_last = index == len(items) - 1
        connector = '└── ' if is_last else '├── '
        
        if item.is_dir():
            lines.append(f"{prefix}{connector}📁 {item.name}/")
            extension = '    ' if is_last else '│   '
            lines.extend(generate_tree(item, prefix + extension, max_depth, current_depth + 1))
        else:
            lines.append(f"{prefix}{connector}📄 {item.name}")
    
    return lines

if __name__ == "__main__":
    project_name = Path.cwd().name
    print(f"📦 {project_name}/")
    tree_lines = generate_tree('.', max_depth=2)
    
    output = f"📦 {project_name}/\n" + '\n'.join(tree_lines)
    print(output)
    
    # Guardar en archivo
    with open('estructura_proyecto.txt', 'w', encoding='utf-8') as f:
        f.write(output)
    
    print("\n✅ Estructura guardada en 'estructura_proyecto.txt'")