You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
teamwk123/python/ls1.py

51 lines
2.1 KiB

4 weeks ago
import os
import sys
#本代码文件实现查看对应用户的文件夹里的文件写成html文件虚拟目录并在每个文件后面生成文件下载链接
l=[]
os.chdir("web") #设置需要查看的目录
a = [x for x in os.listdir() if os.path.isdir(x)]#user文件夹目录下所有用户
print(a)
#f=open("C://Users//12691//Desktop//ui_ref_latest//ui_ref//123admin.html","w", encoding="utf-8")#123admin.html为管理员模式显示的所有文件的页面
#f.write("<head><meta http-equiv='content-type' content='text/html; charset=utf-8' /> <meta name='viewport' content='width=device-width, initial-scale=1.0'><link rel='stylesheet' type='text/css' href='/stylesheets/show.css'><link rel='stylesheet' type='text/css' href='/stylesheets/table.css'></head><body>")
for user in a:
#f.write('</br>User: '+user)
if user!='':#如果用户名有效(不为空)
ff=open(user+'.html','w',encoding='utf-8')
ff.write("<head><meta http-equiv='content-type' content='text/html; charset=utf-8' /> <meta name='viewport' content='width=device-width, initial-scale=1.0'><link rel='stylesheet' type='text/css' href='/stylesheets/user.css'><link rel='stylesheet' type='text/css' href='/stylesheets/table.css'></head><body>User: " +user)
c=os.listdir(user)
if len(c)==0:
print("NULL!\n")
#f.write("</br>该用户云端文件夹为空!"+"</br>")
ff.write("</br>该用户云端文件夹为空!"+"</br>")
else:
for i in c:
print(i)
#f.write("</br>"+i+"<a href='/users/"+user+"/"+i+"' download>下载链接</a>")
#ff.write("</br>"+i+"<a href='/users/"+user+"/"+i+"' download>下载链接</a>")
ff.write("</br>"+i)
print('\n')
#f.write('</br>')
ff.write('</br>')
ff.write('</body>')
ff.close()
b=os.listdir(user)
print("User: " + user)
if len(b)==0:
print("NULL!\n")
#f.write("</br>该用户云端文件夹为空!"+"</br>")
else:
for i in b:
print(i)
print('\n')
#f.write('</body>')
#f.close()