Skip to content

Instantly share code, notes, and snippets.

@BinWang0213
Created May 21, 2020 06:04
Show Gist options
  • Save BinWang0213/93b469f0a6b02ef8fb4348e5cad9e3c4 to your computer and use it in GitHub Desktop.
Save BinWang0213/93b469f0a6b02ef8fb4348e5cad9e3c4 to your computer and use it in GitHub Desktop.
Generate latex dir tree structure
import os
def list_files(startpath):
for root, dirs, files in os.walk(startpath):
if '.git' in dirs: # don't go into any .git directories.
dirs.remove('.git')
level = root.replace(startpath, '').count(os.sep)
indent = ' ' * 4 * (level)
dirname=os.path.basename(root).replace('_','\_')
#print('{}{}{}.'.format(indent, '.%d '%(level+1),os.path.basename(root)))
print('{}{}{}.'.format(indent, '.%d '%(level+1),dirname))
subindent = ' ' * 4 * (level + 1)
for f in files:
print('{}{}{}.'.format(subindent,'.%d '%(level+2), f.replace('_','\_')))
def main():
list_files(os.getcwd())
if __name__ == '__main__':
main()
@BinWang0213
Copy link
Author

Simply run it bypython tree_diretree.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment