tFileArchive - Zip each file in directory into separate .zip files?

Nine Stars

tFileArchive - Zip each file in directory into separate .zip files?

I have a job that looks like: tFileList > tFileArchive which puts the files from a directory into a .zip if I check the ?All Files? option on the tFileArchive component.
Is there a way to zip each file into a separate .zip file?
For example if my folder C:/Talend/ there are the files text1.txt, text2.txt, and text3.txt. I would like the job to make:
C:/Talend/text1.zip
C:/Talend/text2.zip
C:/Talend/text3.zip
To dynamically get all the file names I do the following:
In the file name field, press ctrl+blank space, then select the global variable: tFileList_current_file_path
One Star

Re: tFileArchive - Zip each file in directory into separate .zip files?

Hi,
Un-check the "All Files" option in tFileArchive component. Once this is done, use the current file from the tFileList as the "Filemask" for the tFileArchive component.
Archive file:
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")).replaceAll("\\.txt$", "") + ".zip"

replaceAll is used to remove the file extension, which in this case is ".txt" so that the archive files are created as "text1.zip" and not "text1.txt.zip".
Filemask:
((String)globalMap.get("tFileList_1_CURRENT_FILE"))

This will ensure that the tFileArchive is archiving only the current file.
Attaching screen shots.
Regards,
Abhi
One Star

Re: tFileArchive - Zip each file in directory into separate .zip files?

Hi,
Un-check the "All Files" option in tFileArchive component. Once this is done, use the current file from the tFileList as the "Filemask" for the tFileArchive component.
Archive file:
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")).replaceAll("\\.txt$", "") + ".zip"

replaceAll is used to remove the file extension, which in this case is ".txt" so that the archive files are created as "text1.zip" and not "text1.txt.zip".
Filemask:
((String)globalMap.get("tFileList_1_CURRENT_FILE"))

This will ensure that the tFileArchive is archiving only the current file.
Attaching screen shots.
Regards,
Abhi

Archive file (you could prefer this for case sensitive problems):
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")).substring(0,((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")).length()-4).replaceAll("\\.TXT", "") + ".zip"