One Star

Dynamically Copy files

Hi I need to copy a few files from one directory to another and the list of files to be copied is determined by the result of a SQL query.
I am writing the result of the query to a file. I want to know if I can reference the contents of the file directly in the tFileCopy component.
Right now I am using a tForEach component to include the filemasks which are referenced in a tFileList component - ((String)globalMap.get("tForeach_1_CURRENT_VALUE")). This component is then connected to a tFileCopycomponent and I use the filelist component to get the list of files that need to be copied.
I want to know if there is a way for me to get the list of files straight from a file rather than going through a foreach component.
I tried listing the files in a delimited file and tried using this expression to reference it in the tCopy component. I used this expression ((String)globalMap.get("tFileInputDelimited_1_CURRENT_VALUE")) and ((String)globalMap.get("tFileInputDelimited_1.srcfilename")) but both expressions did not work. Is this possible at all or am I limited to using a foreach component to achieve this kind of a task.
Thanks
3 REPLIES
One Star

Re: Dynamically Copy files

I haven't been able to resolve my problem and I need some help.
I have an input file which has a header and a row with the details of the file. The data in the file is as below.
sourcefilename
D:/Lnx/Talend/TOS-All-r11699-V2.3.1/TOS-All-r11699-V2.3.1/workspace/out.txt
I added a flow to iterate component and connected it to a tfilecopy. However I run into this error when I try this.
Exception in component tFileCopy_2
java.lang.NullPointerException
at java.io.File.<init>(Unknown Source)
at first.dummy.dummy.tFileInputDelimited_1Process(dummy.java:232)
at first.dummy.dummy.runJobInTOS(dummy.java:423)
at first.dummy.dummy.main(dummy.java:342)
Job dummy ended at 12:51 06/05/2008.
Please find attached screenshots of the components.
Community Manager

Re: Dynamically Copy files

Hello
Right now I am using a tForEach component to include the filemasks which are referenced in a tFileList component - ((String)globalMap.get("tForeach_1_CURRENT_VALUE")). This component is then connected to a tFileCopycomponent and I use the filelist component to get the list of files that need to be copied.

Yes, you are creating a right job. If there are different kinds of file, like .csv/.txt, and you want to copy all these kinds of file, you should use a foreach component to iterate all kinds of file.
I tried listing the files in a delimited file and tried using this expression to reference it in the tCopy component. I used this expression ((String)globalMap.get("tFileInputDelimited_1_CURRENT_VALUE")) and ((String)globalMap.get("tFileInputDelimited_1.srcfilename")) but both expressions did not work. Is this possible at all or am I limited to using a foreach component to achieve this kind of a task.

There is not such a global variable: ((String)globalMap.get("tFileInputDelimited_1_CURRENT_VALUE"))
If you want to list all the file path in a delimited file, then iterate them(like you doing in your second post). You can simply create a job as the screenshot.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Dynamically Copy files

Thanks a lot. I just saw your hint about using ctrl+space in text fields in another post and it is really helpful.