同学是做地质的,手中有大把的资料,不过文件太多,让我给帮弄一下PYTHOn脚本,把目录下的所有文件生成html文件来以树形显示。
直接按排:
原代码如下:
import os
def Save2File(pathname,content):
fw = open(pathname,"wt",encoding="utf-8")
fw.write(content)
fw.close()
def WalkDir(dirname):
out =""
try:
ls=os.listdir(dirname)
except:
print ("Access Deny.")
else:
for fn in ls:
temp=os.path.join(dirname,fn)
if (os.path.isdir(temp)):
out += "<h3>"+temp+"</h3>\n"
out +="<ol>\n"
out +=WalkDir(temp)
out +="</ol>\n"
else:
out +="<li><a href=\""+temp+"\">"+fn+"</a></li>\n"
return out
out ="<html><body>\n<ol>\n";
out += WalkDir("D:\\mysql-5.7.29-winx64")
out +="\n</ol>"
Save2File("111111111.html",out);
USB中文网,学习USB技术:http://www.usbzh.com/