Skip to content

Instantly share code, notes, and snippets.

@AkashMV
Created March 9, 2024 16:28
Show Gist options
  • Save AkashMV/c262d0dcc20f5eb157823fa8343f3bd7 to your computer and use it in GitHub Desktop.
Save AkashMV/c262d0dcc20f5eb157823fa8343f3bd7 to your computer and use it in GitHub Desktop.
wanna tell le AI models your project dir structure? scaffolding.py solves this
import os
def generate_ascii_tree(directory, indent=''):
tree = ''
items = os.listdir(directory)
items.sort()
for i, item in enumerate(items):
if(item == 'node_modules'):
tree += f'{indent}{"└──" if is_last else "├──"}{item}/\n'
continue
path = os.path.join(directory, item)
is_last = i == len(items) - 1
if os.path.isdir(path):
tree += f'{indent}{"└──" if is_last else "├──"}{item}/\n'
if is_last:
tree += generate_ascii_tree(path, indent + ' ')
else:
tree += generate_ascii_tree(path, indent + '│ ')
else:
tree += f'{indent}{"└──" if is_last else "├──"}{item}\n'
return tree
if __name__ == '__main__':
current_directory = os.getcwd()
ascii_tree = generate_ascii_tree(current_directory)
print(ascii_tree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment