I\'m trying to use zipfile library on windows 8.1 and python 2.7.9.
I just want to remove library.zip after zipfile.open() but os.remove() throws \"WindowsError [Err
I think you must close your archive before deleting it or exiting the program as it says in python documentation https://docs.python.org/2/library/zipfile.html#zipfile.ZipFile.close
So run z1.close()
and z2.close()
before removing an archive
Your code must look like this:
import os
import zipfile as z
dirs = os.listdir('build/')
bSystemStr = dirs[0]
print("[-] Merging library.zip...")
with z.ZipFile('build/' + bSystemStr + '/library.zip', 'a') as z1:
with z.ZipFile('build_temp/' + bSystemStr + '/library.zip', 'r') as z2:
for t in ((n, z2.open(n)) for n in z2.namelist()):
try:
z1.writestr(t[0], t[1].read())
except:
pass
z2.close()
z1.close()
print("[-] Cleaning temporary files...")
os.remove('build_temp/' + bSystemStr + '/library.zip')
If I'm wrong, correct me.