Python实现遍历目录下所有文件并写到文件中
#coding:utf-8import urllib2import urllibimport osimport shutilhomedir = os.getcwd()import osdef walk_dir(dir,fileinfo,topdown=True): for root, dirs, files in os.walk(dir, topdown): for name in files: print(os.path.join(name)) fileinfo.write(os.path.join(root,name) + '\n') for name in dirs: print(os.path.join(name)) fileinfo.write(' ' + os.path.join(root,name) + '\n')fileinfo = open('list.txt','w')walk_dir(homedir,fileinfo)