Zip Folder with multiple Files

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:

  1. To compress or decompress a single file you can use Iguana built in tools for gzip or bzip2 found here.
  2. There are command line utilities to do some of this as well and you can use io.popen to run these.
  3. I was using a mac with Info zip
    1. Other Utilities are winzip
    2. 7-Zip
    3. Winrar ( a little different but an option)
    4. I believe you canuse Apple unzip also.

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:

Zip_Files_To_Translator.zip

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 🙂

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.