删除同目录下面txt文件(利用os,fnmacth模块)

python学习网 2018-02-21 11:10:01

import os
import fnmatch
for filename in os.listdir('.'):
    if fnmatch.fnmatch(filename, '*.txt'): # 匹配模式为星号,表示任意的字符
        os.remove(filename)

阅读(721) 评论(0)