Search code examples
fileluainsertzip

How can I insert Files into a zip file using Lua


I am writing a script in Lua 5.1 for use with a game engine (EDGE).

I need my script to copy about 20 files into a .miz file (which is really a zipped folder with a set structure) and navigate that structure and copy those files in from a non-zipped folder on the hard drive.

Because Windows 11 it the future I need to use NanaZip rather than 7z which isn't W11 supported.

However, all the examples I've found are for using LUA to zip up files, not insert non-zipped files INTO a zip file without unzipping it.

Is this even possible?


Solution

  • Similar to @koyaanisqatsi I tried it with 7z. You didn't comment on our question on why 7z should be avoided nor whether you are even allowed to use os.execute, but it should provide a good starting point:

    os.execute("7z a yourZip.zip yourFile.png")
    

    Where a is the flag for Add.

    See the manual for other flags like compression: https://linux.die.net/man/1/7z