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


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.