The Talend tFileList component helps you to iterate and read multiple files. If we want to load multiple files from a source whose metadata is the same, then we can use this Talend tFileList component.
To demonstrate the Talend tFileList, we will read three text files and load the data from those files into another text file. The following screenshot shows you the data inside one text file.
Talend tFileList Example
First, drag and drop the tFileList into the Job design space.
The following screenshot shows the tFileList properties available in the components tab.
Within the Directory, we have to select the Directory or folder that holds the required files. Let me click on the … browse button and select the Customers folder.
Under the Talend FileList type, we have three options. If we have only files, then select the first option. When we have subdirectories, select both option or Directories option. And also, checkmark the Include subdirectories option.
Within the Files section, click the Add button and choose the Filemask. Here, we used the *.txt because we want to read all the text files within this folder. If you want all the files *.* (first * for all the files, and the second star for all file extensions).
Use the order by section to change the order of file selection. For now, we choose the order by options by file name.
Next, drag and drop the tFileInputDelimited to read data or records in each text file.
Click on the Edit Schema button and add the Column names, Data type, length, and Precision.
To read one file, we generally choose that file within the File name/Stream section. However, in this scenario, we have to read multiple files, and our filenames are coming from the Talend tFileList. So, when you type t and click control+space, you get the following options. Please select the tFileList1.current_filepath. If you want the file name, then choose the file name.
Please check all the other options of the File input delimited such as field separator, header row, footer row, and row separator.
Here, we used the tLogRow to show the records.
Let me run this Talend tFileList job.
From the above screenshot, you can see all the records. Let me replace the tLogRow with tFileOutputDelimited, and create a new file name with txt extension.
As we are loading data from multiple files, we have to choose the Append option. Next, we need the Header, so we checkmark the Include Header option.
Let me rerun the Talend tFileList job.
You can see the records from all the three text files.
Let me change the Talend tFileList Order action from ASC to DESC (descending), and deleted the CustomersFileList text file.
Now you can see the records stored in a different order.