Skip to content

Instantly share code, notes, and snippets.

@bussiere
Created November 23, 2010 21:49
Show Gist options
  • Save bussiere/712605 to your computer and use it in GitHub Desktop.
Save bussiere/712605 to your computer and use it in GitHub Desktop.
listing files in a directory recursivly not my creation
import os
import stat
def walktree (top = ".", depthfirst = True):
names = os.listdir(top)
if not depthfirst:
yield top, names
for name in names:
try:
st = os.lstat(os.path.join(top, name))
except os.error:
continue
if stat.S_ISDIR(st.st_mode):
for (newtop, children) in walktree (os.path.join(top, name), depthfirst):
yield newtop, children
if depthfirst:
yield top, names
for (basepath, children) in walktree("C:/Users/Bussiere/Documents/docinfo",False):
for child in children:
print (os.path.join(basepath, child).replace("C:/Users/Bussiere/Documents/docinfo",""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment