Five Stars

tFileArchive not working as expected

I have just observed a weird behavior of the tFileArchive component. If the name of the archive file's name contains a space followed by '(#)' where # is a number then the component does not create the archive file.

Below is the test job I have created

tFileArchiveJob.JPG

In this job I have context variables source_filename and destination_filename.

The destination_filename is set based on the source_filename as follows:

EmptyPlaceholder_Properties.JPG

Then the tFileArchive component's properties are set as follows:

tFileArchive_Properties.JPG

Before the job is executed, if I set the name of the context variable source_filename as "archive.zip", then the destination zip file gets created correctly.

However if I set the source_filename as "archive (1).zip", the job executes successfully but no destination zip file is created. Also no error messages are generated.

Can anyone help me out with this issue?

  • Data Integration
1 ACCEPTED SOLUTION

Accepted Solutions
Five Stars

Re: tFileArchive not working as expected

Thanks @aranax your solution did not work but that did give me an idea which worked!

I used the following string in the filemask

"VC_" + context.source_filename.replace(".zip",".csv").replace("(","\\(").replace(")","\\)")

6 REPLIES
Eight Stars

Re: tFileArchive not working as expected

You are using your source_filename context variable as part of your filemask.  If no files match the filemask, no archive is created.

Six Stars

Re: tFileArchive not working as expected

The file mask of tFileArchive is most likely considering the "(1)" as a regex and after evaluation is not able to find the file.

Five Stars

Re: tFileArchive not working as expected

Yes, this is exactly what is happening. Is there a way to tell Talend to ignore the "(" and ")" as special characters?

Eight Stars

Re: tFileArchive not working as expected

You would have to check the string for special characters and escape them.

 

Edit:

According to some searches, you can escape an entire string by wrapping it in \Q...\E.

e.g. "\\Q"+context.source_filename +"\\E"

 

Edit2:

I just tested this, and it doesn't work.

Six Stars

Re: tFileArchive not working as expected

I'm not very good at regex 

but

"CV_"+context.filename.replace(".zip","")+"\\([0-9]\\)"+".zip".replace(".zip",".csv") 

 

will work in the file mask

 

using proper regex  pattern it is possible to have the entire string inside a single string ,I'll look into it later if someone hasn't already replied

Five Stars

Re: tFileArchive not working as expected

Thanks @aranax your solution did not work but that did give me an idea which worked!

I used the following string in the filemask

"VC_" + context.source_filename.replace(".zip",".csv").replace("(","\\(").replace(")","\\)")