-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.py
More file actions
38 lines (33 loc) · 1.28 KB
/
Copy pathindex.py
File metadata and controls
38 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
def html_tree(path,title):
for path,dirs,files in os.walk(path.split("/")[0]):
if os.path.isdir(path):
with open(path+"/index.html", 'w') as f:
f.write("<html>\n <head>\n")
f.write(" <title>%s</title>\n"%title)
f.write(" </head>\n")
f.write(" <body>\n")
f.write(title)
f.write(" <br>")
f.write(" <ul>")
for d in os.listdir(path):
if(os.path.isdir(path+"/"+d)):
s = '\t<li><a href="%s/index.html">%s</a></li>\n'%(d,d)
f.write(s)
elif os.path.isfile(path+"/"+d) and not d.endswith("html"):
s = ('\t<li><a href="%s">%s</a></li>'%(d,d))
f.write(s)
f.write(" </ul>")
f.write(" <br>")
f.write(" </body>\n")
f.write("</html>\n")
if __name__ == "__main__":
#for root, dirs, files in os.walk("."):
# path = root.split(os.sep)
#print(path)
#print(root)
#print((len(path) - 1) * '---', os.path.basename(root))
# for dir in dirs:
# print(root+"/"+dir)
# print(len(path) * '---', file)
html_tree(".","List")