linux how to add a file to a specific folder within a zip file

后端 未结 4 1562
无人及你
无人及你 2021-01-03 20:43

i know how to add a file to the root folder within a zip file:

zip -g xxx.apk yyy.txt

but i\'ve no idea how to specify a particu

4条回答
  •  星月不相逢
    2021-01-03 21:10

    To elaborate on @Ignacio Vazquez-Abrams answer from a year ago, you can use a lower level library, such as the one that comes with Python:

    #!/bin/bash
    python -c '
    import zipfile as zf, sys
    z=zf.ZipFile(sys.argv[1], "a")
    z.write(sys.argv[2], sys.argv[3])
    z.close()
    ' myfile.zip source/dir/file.txt dir/in/zip/file.txt
    

    This will open myfile.zip and add source/dir/file.txt from the file system as dir/in/zip/file.txt in the zip file.

提交回复
热议问题