Posted By

throb on 08/23/10


Tagged

python


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

gartenstuhl
ivor88
rmmjr
Priestd09


Search for files with a specific extension and put them in a list


 / Published in: Python
 

  1. import os
  2.  
  3. def dirLS (dirPath, ext):
  4. files = os.listdir(dirPath)
  5. foundFiles = []
  6. for curfile in files:
  7. try:
  8. prefix, frame, suffix = curfile.split('.')
  9. print suffix
  10. if suffix == ext :
  11. foundFiles.append(dirPath + '/' + curfile)
  12. except:
  13. ''''''
  14. if len(foundFiles) == 0:
  15. foundFiles == None
  16. return foundFiles
  17.  
  18. files = (dirLS('c:/temp','exr'))
  19.  
  20. for file in files:
  21. print file

Report this snippet  

You need to login to post a comment.