Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to rename a file output based on a variable?

I need to (1) make a copy of a file and (2) rename the copied file based on a variable that resides within the file.   I have used the tFileCopy component to copy the file, and also managed to extract the variable from the file e.g. date within the file(report), but I am not sure how I could insert this extracted variable (date) into the tFileCopy component's Destination Filename field.

 

Desperately need guidance to this, thank you

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

If you have successfully extracted the value from the file you need to add to the file name then simply use the tContextLoad to load that value into a predefined context variable.  You can use a tmap with 2 columns to set the context load it needs one column named "key" which should be your predefined context and the second column name is "value" and that equals the value from the file.

 

So at a high level steps

  1. Create Predefined Context named "filenameCTX"
  2. Read file that has value you need and connect that output to a tMap
  3. In tMap have 2 columns (key & value)
  4. Assign key = "filenameCTX" 
  5. Assign value = (value from inside file)
  6. Attach tMap Output to tContextLoad
  7. In tFileCopy component's Destination Filename field use context variable filenameCTX + ".csv"  (for example)

If you have multiple files to do this with you can put steps 2-7 in a subjob and use a tFileList to iterate over the the subjob. 

 

 

you can even put a date stamp on the file as well so do something like filenameCTX + TalendDate.formatDate("yyyy-MM-dd HH:mm:ss",TalendDate.getCurrentDate()) ".csv"  

 

If you need screen shots let me know.

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Hello,

Could you please elaborate your case with an example with input and expected output values?

Best regards

Sabrina

Anonymous
Not applicable
Author

If you have successfully extracted the value from the file you need to add to the file name then simply use the tContextLoad to load that value into a predefined context variable.  You can use a tmap with 2 columns to set the context load it needs one column named "key" which should be your predefined context and the second column name is "value" and that equals the value from the file.

 

So at a high level steps

  1. Create Predefined Context named "filenameCTX"
  2. Read file that has value you need and connect that output to a tMap
  3. In tMap have 2 columns (key & value)
  4. Assign key = "filenameCTX" 
  5. Assign value = (value from inside file)
  6. Attach tMap Output to tContextLoad
  7. In tFileCopy component's Destination Filename field use context variable filenameCTX + ".csv"  (for example)

If you have multiple files to do this with you can put steps 2-7 in a subjob and use a tFileList to iterate over the the subjob. 

 

 

you can even put a date stamp on the file as well so do something like filenameCTX + TalendDate.formatDate("yyyy-MM-dd HH:mm:ss",TalendDate.getCurrentDate()) ".csv"  

 

If you need screen shots let me know.

Anonymous
Not applicable
Author

 Brilliant, thanks heaps for the solution.