So there are a few posts about this, and I tried all the recommended solutions, but none of them seem to work. I am trying to delete a zip archive after I unzip it.
I tried os.remove, os.unlinkwith the help of the operator, witheverything! but i keep getting
WindowsError: [Error 32] The process cannot access the file because it is being used by another process:
Thank you very much in advance
def Unzip(f, password, foldername):
'''
This function unzips a file, based on parameters,
it will create folders and will overwrite files with the same
name if needed.
'''
if foldername != '':
outpath = os.path.dirname(f) + '\\'+ foldername
if not os.path.exists(outpath):
os.mkdir(outpath)
else:
outpath = os.path.dirname(f)
if not os.path.exists(outpath):
os.mkdir(outpath)
if password == '':
z = zipfile.ZipFile(f)
z.extractall(outpath)
z.close()
os.unlink(f)
else:
z = zipfile.ZipFile(f)
z.extractall(outpath, None, password)
z.close()
os.unlink(f)
UPDATE, so I changed the code and this works:
z = zipfile.ZipFile(f)
z.extractall(outpath)
z.close()
del z
os.unlink(f)
source
share