## dirList.py
import os
"""
Author: Feihf
Date : 2014-5-30
"""
""" get Header """
def printHead():
print "<html>"
print "<head><style>a{border:1px solid #FF0099; font-size: 200%;}</style></head>"
print '<body style="background-color:rgb(200,237,204);">'
""" walk the certain dir,and process the dirname """
def printBody(dirname):
try:
ls=os.listdir(dirname)
except:
print('access deny')
else:
for file in ls:
if file == 'index.html':
continue
temp=os.path.join(dirname,file)
if(os.path.isdir(temp)):
print '<a style="background-color:pink;" href="./%s/">%s</a><a href="./%s/readMe.txt">[+]</a><br/>' % (file,file,file)
else:
print '<a href="./%s">%s</a><br/>' % (file,file)
""" get Header """
def printEnd():
print "</body>"
print "</html>"
""" Main"""
dir = os.getcwd()
printHead()
printBody(dir)
printEnd()
@@用法
dirList.py
生成文件的列表(html的格式)