Say I want to add the file file.txt
to foo.zip
, I could just do zip -u foo.zip file.txt
.
However inside the zip-file there already exist a folder with the path foo.zip/very/many/paths/
(relatively to the zip-file).
How would I add file.txt
to the zip-file so it's location inside the zip-file would be foo.zip/very/many/paths/file.txt
?
I could create the directory structure needed first, but isn't there an easier way?
I would normally do it like this:
$ ls file.txt foo.zip $ mkdir very $ mkdir very/many $ mkdir very/many/paths $ cp file.txt very/many/paths $ zip -u foo.zip very/many/paths/file.txt $ rm -rf very
Best Answer
Use Python's zipfile library?
Ok. There is no 'test.zip' right now...
Let's add '/etc/motd' as 'text/motd' to the nonexisting zipfile...
The zipfile library was nice enough to create 'test.zip'.
..and it seems to contain what I wated...
Let's check it by unzipping it to stdout...
Fine!
Now we add a 2nd file...