Advertisement
here2share

# io_filepaths.py

May 6th, 2015
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # io_filepaths.py
  2.  
  3. import os
  4.  
  5. """
  6. This function will generate the file names in a directory
  7. tree by walking the tree either top-down or bottom-up. For each
  8. directory in the tree rooted at directory top (including top itself),
  9. it yields a 3-tuple (dirpath, dirnames, filenames).
  10. """
  11.  
  12. # Walk the tree.
  13. for root, directories, files in os.walk("C:\Program Files\Common Files"):
  14.     for filename in files:
  15.         # Join the two strings in order to form the full filepath.
  16.         filepath = os.path.join(root, filename)
  17.         if filepath.endswith(('.gif','.jpg','.avi','.exe','.htm')):
  18.             print filepath
  19.  
  20. print
  21. print 'Done!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement