我正在尝试从与特定模式匹配的文件夹中删除文件,并遇到以下错误,如何解决此错误?
import os,re,shutil
def purge(dir, pattern):
for f in os.listdir(dir):
print f,pattern
if re.search(pattern, f):
os.remove(os.path.join(dir, f))
dir = '/home/username/chip/com/output/usr/share/firmware/tech/C-1234__s-B2/debug'
patterns =['*.map','*.map-sym-details','*logstrs.bin','*.exe','*.dis']
for pattern in patterns:
purge(dir,pattern)
错误:-
Traceback (most recent call last):
File "files_to_remove.py", line 20, in <module>
purge(dir,pattern)
File "files_to_remove.py", line 5, in purge
if re.search(pattern, f):
File "/usr/local/lib/python2.7/re.py", line 146, in search
return _compile(pattern, flags).search(string)
File "/usr/local/lib/python2.7/re.py", line 251, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat