Update existing 7z archive

Feb 18, 2010 at 1:50 AM

How do I go about updating an existing 7z archive?

Example:

my.7z contains a.txt, b.txt and c.txt .. I now scan a directory and want to update c.txt and add d.txt

var compressor = new SevenZipCompressor();
 if (File.Exists("my.7z"))
     compressor.CompressionMode = CompressionMode.Append;
 else
     compressor.CompressionMode = CompressionMode.Create;
 compressor.CompressFiles(s7zFilename, "c.txt");
 compressor = null;

var compressor = new SevenZipCompressor();
 if (File.Exists("my.7z"))
     compressor.CompressionMode = CompressionMode.Append;
 else
     compressor.CompressionMode = CompressionMode.Create;
 compressor.CompressFiles(s7zFilename, "d.txt");
 compressor = null;

I end up with a my.7z file with a.txt, b.txt, c.txt, c.txt and d.txt (ie.. the c.txt file shows up twice)

How do I go about updating existing files of the same name inside the 7z file?

 

Coordinator
Feb 18, 2010 at 12:51 PM

As a 7z archive is always solid, there is no possible way to update a file except repacking the whole archive.

Feb 18, 2010 at 3:46 PM

Odd since I can drop the same file onto the 7-zip standard interface causing it to update an existing file within a 7z archive.

What is a good way to detect whether a file is already in the 7z archive and then not add it again?  Do I need to open it first using the SevenZipExtractor ?  If so, what method call will get me a listing of current content?

Coordinator
Feb 24, 2010 at 4:07 AM

You should use Extractor.ArchiveFileData or ArchiveFileNames