想要丟棄一組具有特定文件格式的文件。例如,模式列表中列出的那些。如何檢查列表中的模式列表是否存在於我的文件名列表中?
patterns =[r'\.pdf$',r'\.mpeg$']
NOT_FILE = [ re.compile(p) for p in patterns]
grep_not_match = (lambda l, regex: [each for each in l if (regex.search(e)))])
for rt,dr,files in os.walk(rootdirectory):
files = grep_not_match(files,NOT_FILE)
我知道,我在這裏犯了一個超級愚蠢的錯誤,誰能算出來嗎?
媽的。爲什麼我沒有想到但願。 :( 謝謝!! – madCode 2012-02-28 17:33:41