There are many ways to zip files within Iguana. However, when you need to get it done sometimes it is easier to look at someone else’s. So you should know a couple of things ahead of time:
- To compress or decompress a single file you can use Iguana built in tools for gzip or bzip2 found here.
- There are command line utilities to do some of this as well and you can use io.popen to run these.
- I was using a mac with Info zip
The scenario here is that I wanted to compress multiple files into a single zip file. The best way I could think of to do this and to make it as universal as possible it to take an HL7 message and get the patient’s Id (PID-3) and create a folder with that ID and then to create two files and xml and a txt file that contains the patients name and id in an xml format.
The important function is the “zip” function where I send it the folder name. This function will look in that folder and read all the files to build one compressed zip file. I hope this helps but contact me if you have any questions.
Here is the whole project with sample data:
Here is the ‘zip’ function if you would just like a quick peak at it’s contents:
function zip(folder)
--Opens folder and reads in all files and adds to zip
local fld = io.popen([[ls ]]..folder..[[/]])
local allFls = fld:read('*a')
local fls = allFls:split('n')
trace(fls)
local script = [[zip ']]..folder..[[2.zip']]
for i=1, #fls do
script = script..[[ -xi ']]..folder..[[/]]..fls[i]..[[']]
end
io.popen(script..[[ -j]])
end
and a picture for those who like pictures 🙂
