Skip to content

Instantly share code, notes, and snippets.

@kmanalo
Last active January 1, 2016 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmanalo/8103281 to your computer and use it in GitHub Desktop.
Save kmanalo/8103281 to your computer and use it in GitHub Desktop.
Showing the folder tree with Python
# reference http://stackoverflow.com/a/9728478/992834
import os
def list_files(startpath):
for root, dirs, files in os.walk(startpath):
level = root.replace(startpath, '').count(os.sep)
indent = ' ' * 4 * (level)
print('{}{}/'.format(indent, os.path.basename(root)))
subindent = ' ' * 4 * (level + 1)
for f in files:
print('{}{}'.format(subindent, f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment