def all_files(root, patterns='*', single_level=False, yield_folder=False):
# 将模式从字符串中取出放入列表中
patterns = patterns.split(';')
for path, subdirs, files in os.walk(root):
if yield_folder:
files.extend(subdirs)
files.sort()
for fname in files:
for pt in patterns:
if fnmatch.fnmatch(fname, pt):
yield os.path.join(path, fname)
break
if single_level:
break
# fnmatch 来检查文件名匹配模式
# os.path fnmatch os.walk 生成器
thefile=list(all_files(''E:\\projects\\test-log4j\\', '*.class;*.java;*.properties;*.xml'))
for item in thefile:
print item