AllowOverWrite Implementation Question

May 22, 2009 at 4:23 AM

Cheeso,

Why didn't you implement the ability to define whether one can overwrite an existing zip when creating or saving a zip?

For example, it would nice if one could do the following:

ZipFile zip = new ZipFile("zipFileName", false);    // where TRUE=OverWriteExistingFile

or in the Save method:

zip.Save("zipFileName", false);

As it stands now, one has to add code to check whether to use

ZipFile zip = new ZipFile("ZipFileName");

or

ZipFile zip = ZipFile.Read("zipFileName");

 

Just curious, thanks.

--Lenard

 

 

 

 

 

 

Coordinator
May 22, 2009 at 3:01 PM

Hey, Lenard.  Good question.

As it stands now, var zip = new ZipFile("Archive.zip") will succeed whether or not the file Archive.zip exists.

If the file exists, then it will be read in, just as with ZipFile.Read().  If the file does not exist, then it will be created upon Save().

If you want to always overwrite and never read-in the existing zipfile, then use the default ctor, and specify the path in the call to Save().  Like so:

using (var zip = new ZipFile())
{
   zip.AddFile("Foo.txt", "");
   zip.Save("ThisFileWillAlwaysBeOverwritten.zip"); 
}

I think it's a reasonable thing to ask that there be an overwrite flag in the call to Save(). In that case you would get something like this:  

using (var zip = new ZipFile())
{
   zip.AddFile("Foo.txt", "");
   zip.Save("NeverOverwrite.zip", false); // false = throw on existing file
}

... 

Coordinator
May 22, 2009 at 3:03 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
May 22, 2009 at 3:26 PM

Cheeso,

Great!  I didn't realize that var zip = new ZipFile("Archive.zip")did that.  That will work for me.

Thanks.

--Lenard