时间:2021-07-01 10:21:17 帮助过:15人阅读
fnmatch 配合 os.walk() 或者 os.listdir() ,你能做的事太多了,而且用起来相当 easy。
# coding: utf-8
"""
遍历C盘下的所有dll文件
"""
import os
import fnmatch
def main():
f = open('dll_list.txt', 'w')
for root, dirs, files in os.walk('c:\\'):
for name in files:
if fnmatch.fnmatch(name, '*.dll'):
f.write(os.path.join(root, name))
f.write('\n')
f.close()
print 'done...'
if __name__=='__main__':
main()