Primer commit

This commit is contained in:
2025-05-05 02:21:55 +02:00
commit 7b6f525809
62 changed files with 78661 additions and 0 deletions
View File
+30
View File
@@ -0,0 +1,30 @@
import os
def generate_tree(start_path='.', max_depth=2):
lines = []
def _tree(dir_path, depth, prefix):
if depth > max_depth:
return
entries = sorted(os.listdir(dir_path))
for i, entry in enumerate(entries):
path = os.path.join(dir_path, entry)
connector = "└── " if i == len(entries) - 1 else "├── "
lines.append(prefix + connector + entry)
if os.path.isdir(path):
extension = " " if i == len(entries) - 1 else ""
_tree(path, depth + 1, prefix + extension)
lines.append(start_path)
_tree(start_path, 1, '')
return '\n'.join(lines)
def save_tree_to_file(start_path='.', max_depth=2, output_file='tree.txt'):
tree_output = generate_tree(start_path, max_depth)
with open(output_file, 'w', encoding='utf-8') as f:
f.write(tree_output)
print(f"Árbol guardado en: {output_file}")
# Ejemplo de uso:
# Puedes cambiar estos valores según lo necesites
save_tree_to_file(start_path=r'E:\Fitz_Studio', max_depth=3, output_file=r'E:\Fitz_Studio\data\files\txt\tree.txt')