Guest User

Untitled

a guest
Jul 15th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import os
  2. import stat
  3.  
  4. def walktree (top = ".", depthfirst = True):
  5. names = os.listdir(top)
  6. if not depthfirst:
  7. yield top, names
  8. for name in names:
  9. try:
  10. st = os.lstat(os.path.join(top, name))
  11. except os.error:
  12. continue
  13. if stat.S_ISDIR(st.st_mode):
  14. for (newtop, children) in walktree (os.path.join(top, name), depthfirst):
  15. yield newtop, children
  16. if depthfirst:
  17. yield top, names
  18.  
  19. for (basepath, children) in walktree("C:/Users/Bussiere/Documents/docinfo",False):
  20. for child in children:
  21. print (os.path.join(basepath, child).replace("C:/Users/Bussiere/Documents/docinfo",""))
Add Comment
Please, Sign In to add comment