/ 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.
Expand |
Embed | Plain Text
def getFileExtList (dirPath,uniq=True,sorted=True): extList=list() for dirpath,dirnames,filenames in os.walk(dirPath): for file in filenames: fileExt=os.path.splitext(file)[-1] extList.append(fileExt) if uniq: extList=list(set(extList)) if sorted: extList.sort() return extList
You need to login to post a comment.
