Use fnmatch.filter to filter files by more than one possible file extension

后端 未结 8 1800
面向向阳花
面向向阳花 2021-01-31 02:52

Given the following piece of python code:

for root, dirs, files in os.walk(directory):
    for filename in fnmatch.filter(files, \'*.png\'):
        pass
         


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 03:12

    Please try this:

    # pattern_list = ['*.jpg', '__.*']
    def checkFilepatter(filename, pattern_list):
        for pattern in pattern_list:
            if fnmatch.fnmatch(filename, pattern):
                return True
        return False
    

提交回复
热议问题