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 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #!/usr/bin/env python
#coding=ISO-8859-1
import glob
import os.path
def listdirectory(path):
""" Crée une liste des sous-répertoires et fichiers"""
fichier=[]
l = glob.glob(path+'\\*')
for i in l:
if os.path.isdir(i):
fichier.extend(listdirectory(i))
else:
fichier.append(i)
return fichier
def list2html(listdir,path):
""" Transforme une liste en tableau html"""
html_debut="""<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body>
<table style="text-align: left; width: 252px; height: 88px;"
border="1" cellpadding="2" cellspacing="2">
<tbody>"""
html_fin=""" </tbody>
</table>
<br>
</body>
</html>"""
# Exemple de ligne
html_ligne=""" <tr>
<td><a href="file:///C:/test/math/f1.txt">C:/test/math/f1.txt</a></td>
</tr>
"""
fo=open(path,"w")
fo.write(html_debut)
for line in listdir:
fo.write("<tr>"+"\n"+' <td><a href="file:///')
fo.write(line+'">'+line+"</a></td>"+"\n"+"</tr>"+"\n")
fo.write(html_fin)
fo.close()
path="c:\\test"
listdir=listdirectory(path)
list2html(listdir,"test.html") |
Partager