C# 压缩我的文件夹,但不要覆盖C中的现有文件夹#

C# 压缩我的文件夹,但不要覆盖C中的现有文件夹#,c#,directory,overwrite,fastzip,C#,Directory,Overwrite,Fastzip,我使用第三方FastZip来压缩我的文件夹,当我用已有的文件压缩新文件夹时,比如说abc.zip,FastZip覆盖这个旧的abc.zip,删除旧文件,只压缩新文件 任何人都知道解决办法 编辑->我自己设法做到了,如果有人需要,这里有一个解决方案 using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Core; string zipfilename = "abc.zip"; // Your required zip f

我使用第三方FastZip来压缩我的文件夹,当我用已有的文件压缩新文件夹时,比如说abc.zip,FastZip覆盖这个旧的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());
    }
}

压缩之前,您始终可以手动测试文件是否存在:

if (!File.Exists(filename))
    fastZip.CreateZip(filename, @"C:\SourceDirectory", recurse, filter);
else
    //exception or message

这是我正在做的,但是如果(File.Exists(filename))由您决定该怎么办。你想发生什么?