Update all the files in the archive with 7zip
Matthew Harrington
I am using a command line version of 7zip (7za.exe).
I have the following file in the folder:
7za.exe
1.txt
test.ziptest.zip contains several occurrences of 1.txt inside its zipped folder structure.
I need 7zip to update (overwrite) all 1.txt in test.zip with the 1.txt file that is located along the 7za.exe
Could this be done? What is the command? I've tried 7za.exe u test.zip 1.txt, but this only updated 1.txt that lies in the root folder in the archive, but not the inner ones'.
2 Answers
You can specify the file by the switch -si and read from stdin. With a script you can update all the files. But it worked for me only when the type of archive is 7z. Example:
$ 7z l test.7z
7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
(...) Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2016-04-20 17:20:08 ....A 2 8 1.txt
2016-04-20 17:20:08 ....A 2 dir1/1.txt
2016-04-20 17:20:08 ....A 2 dir2/1.txt
2016-04-20 17:20:16 D.... 0 0 dir2
2016-04-20 17:20:14 D.... 0 0 dir1
------------------- ----- ------------ ------------ ------------------------ 6 8 3 files, 2 folders
$ 7z u test.7z -sidir1/1.txt < 1.txt
$ 7z l test.7z
(...) Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2016-04-20 17:20:08 ....A 2 9 1.txt
2016-04-20 17:20:08 ....A 2 dir2/1.txt
2016-04-20 17:22:08 ..... 4 9 dir1/1.txt
2016-04-20 17:20:16 D.... 0 0 dir2
2016-04-20 17:20:14 D.... 0 0 dir1
------------------- ----- ------------ ------------ ------------------------ 8 18 3 files, 2 foldersIn the documentation of 7-Zip 9.20 and 15.14:
Note: The current version of 7-Zip support reading of archives from stdin only for xz, lzma, tar, gzip and bzip2 archives.
LZMA is the default compression method for the 7z archive type. I tried -mm=lzma for zip archive, but it did not work.
7zip -u option does update the archive, but it respects the folder structure. In order to update all text files, you need to recreate the folder structure and place the textfiles in appropriate locations and then zip the entire folder with update option.
If you want to update the 1.txt file a lot of times and update all the files easily, you can use mklink to create junctions to this 1.txt file so that you only need to update the file once.