[英]Excluding files with SevenZipSharp in Code
I'm currently on a little project where I have to define several paths that need to be compressed into one single zip-file. 我目前在一个小项目中,必须定义几个路径,这些路径需要压缩到一个单独的zip文件中。
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. 我已经尝试过类似的方法,但是争论似乎只存在于cmd中。
compressor.CustomParameters.Add("-x", "@C:\\Users\\******\\Desktop\\exclude.txt");
I didn't find any possibility with SevenZipSharp to exclude files. 我没有发现使用SevenZipSharp排除文件的任何可能性。 Instead I use now DotNetZip which has a nice method to remove files: ZipFile.RemoveEntry()
and ZipFile.RemoveEntries()
eg: 相反,我现在使用DotNetZip,它具有删除文件的好方法: ZipFile.RemoveEntry()
和ZipFile.RemoveEntries()
例如:
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);
}
}
I found that SevenZipSharp can exclude files: 我发现SevenZipSharp可以排除文件:
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.