python 文件解压缩到指定路径中文名乱码的问题
程序员文章站
2022-05-31 17:25:50
...
import zipfile
import os
from pathlib import Path
def ZipFiles(req):
fileser=req.FILES['file']
z=zipfile.ZipFile(fileser, 'r')
# logger = logging.getLogger("upmsg")
user = UserAccountTB.objects.filter(id=req.user_id).first()
with z as f:
for fn in f.namelist():
try:
an = unicode(fn, 'cp936')
Path(f.extract(member=fn, path='./static/certif_file/')) #解压到指定路径的文件不能正常访问
if fn.endswith('jpg'):
dirfile='./static/certif_file/'+str(fn) #修改前路径名称包括文件
abs = './static/certif_file/' + str(an) #修改后的名称
os.renames(dirfile, abs) #更改名称
return JsonResponse({"ret":0,'msg':'success'})