4

I would like to add a large number of files with different names from different folders to a single 7-Zip archive using 7za.exe. This should be simple, but it turned out to be a major pain.

I created a file that contains the paths (7za a out.7z @list.txt), but once there are too many (~100) files, it fails. Apparently the content of the argument file is pushed onto the command line buffer [Edit: This was likely a misinformation on my part, either way it was not the reason], which is far too small (the number of files to add is more than one million).

Splitting the process up by adding the files one by one is not feasible due to the way 7za works: When adding the next file, it creates a copy of the archive, adds the file to the copy and finally replaces the original. This is terribly slow once the archive gets to a couple 100 MB in size.

So far I am using a combination of the two approaches by adding a dozen files each time in a loop, but it is an unreliable hack and still very slow. Is there a better way to do it?

I tried to use 7-Zip wrapper DLLs (I'm a C# programmer), but none of them worked reliably and I was repeatedly suggested to just use 7za instead.

mafu
  • 2,855

1 Answers1

4

Due to the stupid way I approach the problem it took me a lot of time to figure out the real reason. It is due to a bug in 7zip at a place I did not think of.

There is a wrong error notification if using a listfile in cli version 4.57. If a listfile contains some lines of absolute paths (it seems that relative pathes are working) which point to a same named files in different directories a 'Duplicate filename' error comes up.

I was able to reproduce the problem using any two files of the same name in different directories with their absolute path in the listfile.

In the original question, when adding only 1 or few files at a time, it worked (the archive file itself was created without problems) since the listfile (accidentally) did not contain any such "duplicate filenames".

Officially, it is called a feature. While I am uncertain about that, it was without doubt confusing me and others due to it being undocumented.

mafu
  • 2,855