cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Using Zip Writer snap without file structure

mtran21
New Contributor III

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
image

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

4 REPLIES 4

j_angelevski
Contributor III

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โ€™]
image

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

image

mtran21
New Contributor III

Thank you @j.angelevski
It is working great.

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

j_angelevski
Contributor III

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