SharpZipLib 文件/文件夹 过滤

这里就不说压缩/解压了。网上教程太多。

主要说一下,解压时,如何过滤某些文件/文件夹

参考地址:https://github.com/icsharpcode/SharpZipLib/wiki/FastZip

主要内容:

解压时:过滤文件

以下表达式包含所有以“.dat”结尾的名称,但“dummy.dat”除外

// To conditionally extract files in FastZip, use the fileFilter and directoryFilter arguments.
    // The filter is a list of regex values separated with semi-colon. An entry starting with - is an exclusion.
    // See the NameFilter class for more details.
    // The following expression includes all name ending in '.dat' with the exception of 'dummy.dat'
    string fileFilter = @"+\.dat$;-^dummy\.dat$";
    string directoryFilter = null;
    bool restoreDateTime = true;
 
    // Will prompt to overwrite if target filenames already exist
    fastZip.ExtractZip(zipFileName, targetDir, FastZip.Overwrite.Prompt, OverwritePrompt,
                       fileFilter, directoryFilter, restoreDateTime);

解压时:过滤文件夹

以下是解压时,过滤Download和Upload文件夹

(new FastZip()).ExtractZip(downloadFile, UnPath, FastZip.Overwrite.Always, null, "", @"-Download;-Update", true);

猜你喜欢

转载自www.cnblogs.com/hanjun0612/p/11722586.html
今日推荐