Заархивируйте мою папку, но не перезаписывайте существующую в C#

Я использую FastZip стороннего производителя, чтобы заархивировать свою папку, когда я заархивирую новую папку с уже существующим файлом, скажем, abc.zip, Fast Zip перезаписает этот старый abc.zip, удалит старые файлы и заархивирует только новые файлы.

Любой знает решение.

РЕДАКТИРОВАТЬ-> Мне удалось сделать это самостоятельно, вот решение, если кому-то нужно.

using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Core;

string zipfilename = "abc.zip"; // Your required zip file
string fdrname = "abc";

if (!File.Exists(zipfilename)) // If file zip does not exists
{
    Directory.CreateDirectory(fdrname); // Create folder with same name
    FastZip fz = new FastZip();         // using FastZip dll
    fz.CreateZip(zipfilename, fdrname, true, null); // create zip file (ofcourse its empty)
}
if (Directory.Exists(fdrname)) // delete folder which you have created (optional)
    Directory.Delete(fdrname);

    try
    {
        ZipFile zip = new ZipFile(zipfilename); // by Using ZipFile dll
        zip.BeginUpdate();
        zip.Add(pathtofile); // add file path which you want to zip in abc.zip
        zip.CommitUpdate();
        zip.Close();
    }
    catch (Exception e)
    {
        Console.WriteLine((e.ToString());
    }
}

1 ответ

Вы всегда можете вручную проверить существование файла перед архивированием:

if (!File.Exists(filename))
    fastZip.CreateZip(filename, @"C:\SourceDirectory", recurse, filter);
else
    //exception or message
Другие вопросы по тегам