Created
March 18, 2009 14:26
-
-
Save seanh/81152 to your computer and use it in GitHub Desktop.
Recursively walk a directory in Python with os.walk.
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
"""Recursively walk a directory with os.walk.""" | |
import os | |
base_dir = '/home/seanh' # The directory to walk | |
for root, dirs, files in os.walk(base_dir): | |
print 'root: ',root | |
print ' dirs:' | |
for d in dirs: | |
print ' ',d | |
print ' files:' | |
for f in files: | |
print ' ',f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment