使用 zipfile 模块,我创建了一个脚本来提取我的存档文件,但该方法破坏了除 txt 文件之外的所有内容。
def unzip(zip):
filelist = []
dumpfold = r'M:\SVN_EReportingZones\eReportingZones\data\input\26012012'
storage = r'M:\SVN_EReportingZones\eReportingZones\data\input\26012012__download_dump'
file = storage + '\\' + zip
unpack = dumpfold + '\\' + str(zip)
print file
try:
time.sleep(1)
country = str(zip[:2])
countrydir = dumpfold + '\\' + country
folderthere = 0
if exists(countrydir):
folderthere = 1
if folderthere == 0:
os.makedirs(countrydir)
zfile = zipfile.ZipFile(file, 'r')
## print zf.namelist()
time.sleep(1)
shapepresent = 0
在这里我有一个问题 - 通过读取和写入压缩数据,zipfile 命令似乎使其无法被相关程序使用 - 我正在尝试解压缩 shapefile 以在 ArcGIS 中使用...
for info in zfile.infolist():
fname = info.filename
data = zfile.read(fname)
zfilename = countrydir + '\\' + fname
fout = open(zfilename, 'w')# reads and copies the data
fout.write(data)
fout.close()
print 'New file created ----> %s' % zfilename
except:
traceback.print_exc()
time.sleep(5)
是否可以使用系统命令调用 WinRar 并让它为我解包?干杯,亚历克斯
编辑
使用 wb 方法后,它适用于我的大多数文件,但有些文件仍然被损坏。当我使用 winRar 手动解压缩有问题的文件时,它们会正确加载,并且它们还会显示更大的文件大小。
请有人指出我加载winRar的方向以完成完整的解压缩过程吗?