#!/usr/bin/env python # -*- coding: UTF-8 -*- import os import fnmatch def all_file(root, patterns=‘*‘, single_level=False, yield_folders=False): patterns = patterns.split(‘;‘) for path, subdirs, files in os.walk(root): if yield_folders: files.extend(subdirs) files.sort() for name in files: for pattern in patterns: if fnmatch.fnmatch(name, pattern.strip()): # 去除pattern两端的空格 yield os.path.join(path, name) if single_level: break if __name__ == ‘__main__‘: for path in all_file(os.getcwd(), ‘*.pyc‘): os.remove(path)
时间: 2024-11-05 23:19:21