0

我正在使用第三方 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());
    }
}
4

1 回答 1

2

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

if (!File.Exists(filename))
    fastZip.CreateZip(filename, @"C:\SourceDirectory", recurse, filter);
else
    //exception or message
于 2013-10-10T09:28:58.817 回答