您的位置:首页 > 编程语言 > Python开发

python之生成文件列表(链接方式)

2015-11-18 22:47 567 查看
## 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的格式)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: