Question

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");
Was it helpful?

Solution

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

OTHER TIPS

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. 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top