用代码中的SevenZipSharp排除文件 [英] Excluding files with SevenZipSharp in Code

查看:65
本文介绍了用代码中的SevenZipSharp排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在一个小项目中,我必须定义几个路径,这些路径需要压缩到一个单独的zip文件中.

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?

我已经尝试过类似的方法,但是争论似乎只存在于cmd中.

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

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

推荐答案

我发现SevenZipSharp无法排除文件.相反,我现在使用DotNetZip,它具有删除文件的好方法: ZipFile.RemoveEntry() ZipFile.RemoveEntries()例如:

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);
    }
}

这篇关于用代码中的SevenZipSharp排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆