Skip to content

Instantly share code, notes, and snippets.

@bwesterb
Created October 31, 2014 07:10
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 bwesterb/a699d64fe1d7d4f78bb9 to your computer and use it in GitHub Desktop.
Save bwesterb/a699d64fe1d7d4f78bb9 to your computer and use it in GitHub Desktop.
recurse through directories
#!/bin/python
import os
import os.path
base_path = '.'
todo = [base_path]
while todo:
current_dir = todo.pop()
for child_name in os.listdir(current_dir):
child = os.path.join(current_dir, child_name)
if os.path.isdir(child):
todo.append(child)
continue
if os.path.isfile(child):
# Do the thing with the file
# ....
print child
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment