Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtractExistingFileAction.OverwriteSilently is not overwriting the files in a given directory

I have a solution for updating an application that uses the API DotNetZip (http://dotnetzip.codeplex.com/) for handling ZIP files. One method is to overwrite files in certain folders as follows.

ZipFile zipFile = ZipFile.Read(file);
    {
        foreach (ZipEntry zipEntry in zipFile)
        {
            zipEntry.Extract(@"C:\IASD\CantinaEscolar", ExtractExistingFileAction.OverwriteSilently);
        }
    }

Where: @ "c: \ SDA \ CantinaEscolar" is where are unzipped the files inside the zip (files).

Now, if the directory already contains a file with the same name that will be unpacked, the application is returning an error related to the file already exists in the directory.

System.IO.IOException: The file 'c:\IASD\CantinaEscola\nomedoarquivo.exe' already exists

OverwriteSilently This method should not override the unzipped files silently (without requesting user confirmation)?

Or: Is there any way to force this overwritten within the directory (-type f or something)?

If you possess any other tips on how to accomplish this task, I will be grateful.

like image 778
Paulo Romeiro Avatar asked Apr 04 '14 14:04

Paulo Romeiro


1 Answers

OverwriteSilently can overwrite a file. It won't throw an Exception if the file is already present even if the the file is readonly.

What it cannot do is:

  • overwrite if the unzipping is done under the credentials that does not allow it.
  • overwrite when the file is in use.

The latter could very well be the case for the file "nomedoarquivo.exe". This executable could be running while trying to overwrite.

like image 120
sunnyhighway Avatar answered Oct 03 '22 06:10

sunnyhighway