Excluding files with SevenZipSharp in Code

情到浓时终转凉″ 提交于 2020-01-16 06:11:18

问题


I'm currently on a little project where I have to define several paths that need to be compressed into one single zip-file.

Now the following case: One of those paths is a directory, which should be compressed recursively (including all files and sub-folders it contains). Before I compress, I check several things including permissions. If the current user, which wants to compress, doesn't have the permission to a file or folder it should be excluded.

Now how can I exclude several files and directories from compressing in recursive mode?

I already tried something like this, but the arguement seems to exist only in cmd.

compressor.CustomParameters.Add("-x", "@C:\\Users\\******\\Desktop\\exclude.txt");

回答1:


I didn't find any possibility with SevenZipSharp to exclude files. Instead I use now DotNetZip which has a nice method to remove files: ZipFile.RemoveEntry() and ZipFile.RemoveEntries() e.g.:

foreach (string removePath in Verifier.ExcludePaths)
{
    try
    {
        // Remove files and directories to be excluded
        zipFile.RemoveEntry(removePath);
    }
    catch (Exception)
    {
        Logger.Warn("Could not exclude path \"{0}\".",removePath);
    }
}



回答2:


I found that SevenZipSharp can exclude files:

SevenZipCompressor sevenZipCompressor = new SevenZipCompressor();
sevenZipCompressor.ModifyArchive(archiveName, dictionary);
// string archiveName: archive name
// Dictionary<int Index, string NewFileName>: NewFileName or Null value to delete the corresponding index. 


来源:https://stackoverflow.com/questions/14931577/excluding-files-with-sevenzipsharp-in-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!