1 Star 3 Fork 2

HashuaiboY/文件上传demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DeletingUnnecessaryFiles.py 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
HashuaiboY 提交于 2022-05-16 21:01 . fixed
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/hashuaiboy/file-upload-demo.git
git@gitee.com:hashuaiboy/file-upload-demo.git
hashuaiboy
file-upload-demo
文件上传demo
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385