แนวคิดในการทำ
เมื่อเราทำการรันโปรแกรมนี้ โปรแกรมจะไปดูที่อยู่ปัจจุบันของโปรแกรมที่ทำการรันนี้ หลังจากได้ที่อยู่ปัจจุบันแล้วโปรแกรมจะทำการค้นหาไฟล์หรือ Directory ทั้งหมด แล้วนำชื่อของไฟล์หรือ Directory ไปสร้างเป็น Link ในไฟล์ html
import os,sys
currPath=os.getcwd()
str_temp=""
for f in os.listdir(currPath):
str_temp=str_temp+"<a href=./"+f+">"+f+"</a><br>"
file_html="""
<html>
<head><title>Directory</title></head>
<body>"""
file_html=file_html+str_temp+"</body></html>"
html=open('work2_1.html','w')
html.write(file_html)
html.close()
print"DONE..."
ตัวอย่างเมื่อทำการ RUN
ไม่มีความคิดเห็น:
แสดงความคิดเห็น