Posted By

cieux-gris on 09/03/08


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

carlosabargues
danielalexwood
Achayan


Get directory file extension list


 / Published in: Python
 

Given a directory path and two switches, return a list of the extensions for all files in the directory, recursing down into its subdirectories. Optionally make a unique list. Optionally sort the list.

  1. def getFileExtList (dirPath,uniq=True,sorted=True):
  2. extList=list()
  3. for dirpath,dirnames,filenames in os.walk(dirPath):
  4. for file in filenames:
  5. fileExt=os.path.splitext(file)[-1]
  6. extList.append(fileExt)
  7.  
  8. if uniq:
  9. extList=list(set(extList))
  10. if sorted:
  11. extList.sort()
  12. return extList

Report this snippet  

You need to login to post a comment.