c# - 使用 FastZip 压缩目录,并且只包含某些文件类型(文件过滤)

标签 c# fastzip

不知道有没有办法用fastzip压缩一个目录,但只包括某些文件类型。我正在考虑使用类似的东西:

    public static void ZipFiles(string DirectoryToZip, string ZipedFile, string fileFilter, string folderFilter) {
        FastZip fz = new FastZip();
        fz.CreateEmptyDirectories = true;
        fz.CreateZip(ZipedFile, DirectoryToZip, true, fileFilter, folderFilter);
    }

唯一的问题是 fileFilter 是在 string 中给出的,而不是在 arrays 中。

有什么想法吗?

最佳答案

我解决了我自己的问题;事实证明,我只需要提供一个正则表达式字符串来过滤我想要的类型。

这里是一个只包含 excel 文件、word 文件和 xml 文件到 zip 中的例子。

        FastZip fz = new FastZip();
        fz.CreateEmptyDirectories = true;

        fz.CreateZip(zipFile, prjDir, true, ".*\\.(xls|doc|xml)$", "");

关于c# - 使用 FastZip 压缩目录,并且只包含某些文件类型(文件过滤),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1671491/

相关文章:

c# - 如何将基于 char** 的数组从基于 C 的 dll 转换为等效的 C#?

c# - 在 DataTable 中加载 DataReader 时出现约束异常

c# - 使用标题列表,用于切换

c# - 使用 SQL 或 C# 计算 - 多列和多行

c# - 在 C# 中为 double 添加千位分隔符