代码拉取完成,页面将自动刷新
import os
import pymysql
def selectAllFiles(db):
cursor = db.cursor()
sql = "select * from files"
try:
cursor.execute(sql)
results = cursor.fetchall()
allfiles = []
for row in results:
allfiles.append(row[1])
return allfiles
except:
return None
def selectUsefulFiles(db):
cursor = db.cursor()
sql = "select * from user"
try:
cursor.execute(sql)
results = cursor.fetchall()
allfiles = []
for row in results:
allfiles.append(row[2].split("/")[-1])
return allfiles
except:
return None
def deleteAction(list):
basedir = "E://images/"
for file in list:
filepath = basedir + file
if(os.path.isfile(filepath)):
os.remove(filepath)
print("delete done")
def application():
db = pymysql.connect(host="localhost",user="root",password="",database="uploads")
allFiles = selectAllFiles(db)
allUsefulFiles = selectUsefulFiles(db)
willBeDeleted = []
for row in allFiles:
if(row not in allUsefulFiles):
willBeDeleted.append(row)
deleteAction(willBeDeleted)
print("script done")
if __name__ == '__main__':
application()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。