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
image

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

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
image

image

4 Likes

Thank you @j.angelevski
It is working great.

@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.
image

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.
image

Then in the child pipeline just add the zip file writer snap.
image
image
Here ‘_count’ refers to the parameter passed from the parent pipeline.

Result would be:
image

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

Hope this answers your question.