forked from Donhackerug/Js-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
31 lines (23 loc) · 957 Bytes
/
index.py
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
import os
def generate_directory_structure(directory):
structure = []
for root, dirs, files in os.walk(directory):
# Exclude the .git directory
dirs[:] = [d for d in dirs if d != '.git']
# Build the directory path
path_parts = root.replace(directory, '').strip(os.sep).split(os.sep)
indent = ' ' * len(path_parts)
if dirs or files:
structure.append(f'{indent}- **[{os.path.basename(root)}]**')
# Add Markdown files within this directory
for f in files:
if f.endswith('.md'):
file_indent = ' ' * (len(path_parts) + 1)
structure.append(f'{file_indent}- {f}')
return '\n'.join(structure)
directory = '.' # Replace with the path to your directory
structure = generate_directory_structure(directory)
output = f'# Directory Structure\n\n{structure}'
with open('help.md', 'w') as f:
f.write(output)
print(output)