python26列出目录下文件到txt
时间:2010-12-21 来源:iTech
代码:
import osdef ListFilesToTxt(dir,file,wildcard,recursion):
exts = wildcard.split(" ")
files = os.listdir(dir)
for name in files:
fullname=os.path.join(dir,name)
if(os.path.isdir(fullname)):
ListFilesToTxt(fullname,file,wildcard,recursion)
else:
for ext in exts:
if(name.endswith(ext)):
file.write(name + "\n")
break
def Test():
dir="C:\\Python26\libs"
outfile="binaries.txt"
wildcard = ".py .exe .dll .lib"
file = open(outfile,"w")
if not file:
print "cannot open the file %s for writing" % outfile
ListFilesToTxt(dir,file,wildcard, 1)
file.close()
Test()
欢迎大家改进共享!
相关阅读 更多 +