from asyncio.windows_events import NULL
import os
import sys

from psutil import users
#本代码文件实现查看对应用户的文件夹里的文件,写成html文件(虚拟目录),并在每个文件后面生成文件下载链接
l=[]
os.chdir("C://Users//12691//Desktop//ui_ref//users") #设置需要查看的目录
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!=NULL:#如果用户名有效(不为空)
        ff=open('C://Users//12691//Desktop//ui_ref//public//contents//'+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("C://Users//12691//Desktop///ui_ref//users//"+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("C://Users//12691//Desktop//ui_ref//users//"+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()