Search code examples
loopsdirectorytalend

Loop through a directory in Talend


I have a Directory with many sub-directories in it including one named as OLD. This OLD folder could also be inside any of the sub directories and contains archived files.

  • Root Directory A
    • SUB-DIRECTORY A
      • file1.txt
      • file2.txt
    • SUB-DIRECTORY B
      • file1.txt
      • file2.txt
      • OLD
    • SUB-DIRECTORY C
      • file1.txt
      • file2.txt
    • SUB-DIRECTORY D
      • file1.txt
      • OLD
      • SUB-SUB-DIRECTORY E
        • file7.txt
        • OLD

I need to create a job in Talend which shall look for all OLD folders (in main and in sub directory both) and delete the files from that folder. I can use tFilelist to and mask the files to be deleted. But unable to figure out how to configure the job to look for OLD folder in all sub directories and delete those files also.


Solution

  • What you need to do is in the tFileList put your main folder choose check box include sub directories and in the FileList type drop down list choose Directories. Your file mask should be "OLD" or if it is anything more "OLD". Iterate and use the parameter ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) to capture your sub directories. Now you can use this folder path in a tFileDelete Which can also delete folders