Created
May 21, 2020 06:04
-
-
Save BinWang0213/93b469f0a6b02ef8fb4348e5cad9e3c4 to your computer and use it in GitHub Desktop.
Generate latex dir tree structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simply run it by
python tree_diretree.py