У меня есть zip-файл с указанием пути.Когда я распаковываю файл с помощью python и помещаю его в свою целевую папку, он создает все файлы в пути внутри моей целевой папки.
Target: d: \ unzip_files В zip-файле есть путь и имя файла.из: \ NIS \ TEST \ Files \ tnt.png
Что происходит: d: \ unzip_files \ NIS \ TEST \ Files \ tnt.png
Есть ли способ сделать это просто распаковатьфайл tnt.png в d: \ unzip_files?Или мне придется прочитать список и переместить файл, а затем удалить все пустые папки?
import os, sys, zipfile
zippath = r"D:\zip_files\test.zip"
zipdir = r"D:\unzip_files"
zfile = zipfile.ZipFile(zippath, "r")
for name in zfile.namelist():
zfile.extract(name, zipdir)
zfile.close()
Итак, вот что сработало ..
import os, sys, zipfile
zippath = r"D:\zip_files\test.zip"
zipdir = r"D:\unzip_files"
zfile = zipfile.ZipFile(zippath, "r")
for name in zfile.namelist():
fname = os.path.join(zipdir, os.path.basename(name))
fout = open(fname, "wb")
fout.write(zfile.read(name))
fout.close()
Спасибо запомощь.