Forum Discussion

mtran21's avatar
mtran21
New Contributor III
5 years ago

Using Zip Writer snap without file structure

I am trying to use a Zip Writer snap zip a .txt file to become .zip file.
So if my txt file location is /intshare/test/watermarkout//test.txt, when I zip it, the folder structure comes with the zip.

Here is my snap

and when I unzip it, it has folder structure

How do I not include the folder structure with the zip file? I just want file test.txt in the root of the zip.

Thanks

4 Replies

  • Use a mapper with binary output before ZipFile writer snap and map the content-location of your file:
    $[‘content-location’].substr($[‘content-location’].lastIndexOf(“/”) + 1) ----> $[‘content-location’]

    Then in the zip file write, just enter the filename of the archive folder

    • mtran21's avatar
      mtran21
      New Contributor III

      @j.angelevski So I did tried this and it looks like it zipped all the files together in 1 zip file.
      Is there a way to have each input file its own zip file?

      For example, my input are test1.txt and test2.txt. I like to be able to produce 2 zip files. test1.zip and test2.zip.

      Thanks

  • @mtran21,
    Zip File Writer puts all binary input files into one zipped file, a workaround for this I think it would be if you create a child pipeline with binary input and in that pipeline put the Zip File Writer snap.

    Here I use a MultiFile Reader.

    The configuration of the mapper stays the same. But now instead of using a zip file writer you use a pipeline execute to execute the child pipeline. The configuration of the pipeline execute is really straightforward, just choose the child pipeline and pass the ‘count’ parameter with a value ‘snap.in.totalCount’, this function counts the number of input documents.

    Then in the child pipeline just add the zip file writer snap.


    Here ‘_count’ refers to the parameter passed from the parent pipeline.

    Result would be:

    This will create x number of zip files for every input document.

    Hope this answers your question.