(由Ai生成部分,再改成适合自己用)
index.py
# -*- coding: utf-8 -*-
import os
# import sys
path = 'E:\BIT\public\software\\'
# path = path = os.getcwd()
# path = os.getcwd().replace('\\','/')
# current_directory = os.path.dirname(os.path.abspath(__file__))
# root_path = os.path.abspath(os.path.dirname(current_directory) + os.path.sep + ".")
# sys.path.append(root_path)
# path = sys.path[0]+"\\"
# print(sys.path[0])
print(path)
f = open("本地目录.html", "w", encoding="utf-8")
f.write('<!DOCTYPE html><html lang="zh-CHS"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><style> a { color: #333; text-decoration: none}a:hover { color: #777}</style></head>\n')
f.write('<body style="padding: 50px;">\n')
f.write('<pre>\n')
f.write('<h1 style="color: brown;">\n')
f.write('软件目录\n')
f.write('</h1>\n')
f.write('<code>\n')
f.write('<br>\n')
for root, dirs, files in os.walk(path):
level = root.replace(path, '').count(os.sep)
indent = '----' * 4 * (level)
ba =os.path.basename(root)
print(ba)
f.write('{}<b style="color: chocolate;">{}</b>\n'.format(indent, os.path.basename(root)))
subindent = '<a href="' * 1 * (level + 1) + ba
for file in files:
print(file)
f.write('{}/{}">{}</a>\n'.format(subindent, file, file))
f.write('<br>\n')
f.write('</code>\n')
f.write('</pre>\n')
f.write('</body>\n')
f.write('</html>\n')
f = open("index.html", "w", encoding="utf-8")
subindent = '<a href="software/' * 1 * (level + 1) + ba
# software/ 超链接地址加目录
# index.html 默认自己找
方便放入静态包里访问 http://127.0.0.1:3000/sofware
pip install pyinstaller??
#?安装最新依赖包
pyinstaller -F --i logo.ico index.py
# -F?是打包成单个文件 --i xx.ico?换上自己的logo图标