Cannot delete files after extracting

Jan 8, 2010 at 9:21 AM
Edited Jan 8, 2010 at 9:22 AM



I am currently running into an awkward situation: after I extract the zip file (multivolume) I cannot delete the source zip files. This works great with saving, after which I move the resulting zip files from the temp folder to the desired target.


The code I'm using is as follows:



public void UnZipFiles(string zipPathAndFile, string outputFolder)
using (ZipFile zip = ZipFile.Read(zipPathAndFile))
                foreach (ZipEntry e in zip)
 } }
The goal is to zip a huge file, send it to the server in small pieces and then unzip it on the server.

After the unziping I'm moving the resulting files and cleaning up the zip files to save space.

Its the last step that is failing. I'm deleting with Directory.Delete(target,true).

Is this some kind of bug in DotNetZip or am I missing something?

Besides this small issue all is working great.

Thank you very much.

Edit: I'm using Ionic.Zip.dll version


Jan 8, 2010 at 1:10 PM
Edited Oct 14, 2010 at 9:02 PM

Well, it might be a bug in DotNetZip, but I have no way to know.

You didn't say why the Delete is failing.  Normally there's an exception, indicating the reason it failed.  If it's a problem with permissions, then you'll get a message to that effect. IF the problem is that the file to be deleted is still open, you'd get a message indicating that.   I might be able to help diagnose if you provided the exception and stacktrace.

In theory it could be that the file is still being held open by DotNetZip, preventing the delete.  But I think that is unlikely.   

If I were troubleshooting this, I might see if it is possible to create the zip and then delete it, without unzipping in between.  If you factor out the unzipping, and it can be deleted, then it points to DotNetZip as the cause.  If you remove the unzipping, and it still cannot be deleted, then it would indicate that it is not DotNetZip.  This wouldn't be definite, but it would be a good indication, one way or the other.

good luck


Oct 13, 2010 at 6:53 AM

I had exactly the same problem. After extracting the files in a zip, I tried to manually delete the files but the system complains that the file is still being used by another process.

I tried all the sample code proposed on the posts but nothing works. The zip file itself can be deleted but not the extracted files. Can anyone help?

Oct 13, 2010 at 9:43 AM

I have the same problem.

The Zip file can't be deleted after it is being extracted (only if the zip file is composed of several segments).

when i don't extract the zip file , i can delete it successfully.

Oct 14, 2010 at 9:04 PM

You two are NOT describing the same problem.  You both are having trouble deleting files, but not the same files. The former is having trouble deleting EXTRACTED files.  The latter is having trouble deleting the zip file from which files were extracted.  Both of these are independent of the prior discussion, from January. 

I suggest you each open unique threads to discuss and investigate your unique situations.

If I try to reply to all of you on one thread, none of us will be clear on what is being asked, and what is being answered.