Created
August 23, 2013 09:42
-
-
Save chehab/6317448 to your computer and use it in GitHub Desktop.
Go through every file and subdirectory in a directory tree
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 | |
for dirname, dirnames, filenames in os.walk('.'): | |
# print path to all subdirectories first. | |
for subdirname in dirnames: | |
print os.path.join(dirname, subdirname) | |
# print path to all filenames. | |
for filename in filenames: | |
print os.path.join(dirname, filename) | |
# Advanced usage: | |
# editing the 'dirnames' list will stop os.walk() from recursing into there. | |
if '.git' in dirnames: | |
# don't go into any .git directories. | |
dirnames.remove('.git') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment