Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Tasfiahm
Creator
Creator

How to create a job that's going to read file list from a directory and copy the file individually in the specified folders using pattern.

I am design a job which is going to read a file list and base on the name of the file its is going to copy the file in a desired location.

Requirement: Read files from a common folder location and copy them in multiple folder depending on the name/pattern of the file

example:

input file name:

apple.csv

yellow.csv

green.csv

All the file are in the same source folder.

The basic design is :

tfilelist >> iterate --- tfileCopy

tfilelist setup:

File mask -- apple.csv

Now the challenge is route it on the basis of the file name. The easy and inefficient way is to add (3) multiple tfileList component with file mask.

But this is not the best approach as there may be 50+ files and 50+ destinations. I need to read the file list one time and then route the file on the

basis of file name to multiple folder

So what will be the best approach to solve the problem.

Labels (4)
2 Replies
Anonymous
Not applicable

@tas ahm​, set the file mark as "*.csv", it will iterate all files with extension ".csv". There are some global variables predefined on the component, you can use them directly on other component. for example:

current file name: ((String)globalMap.get("tFileList_1_CURRENT_FILE"))

current file path: ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

 

So, if you want to copy the file to specified folder based on the file name, you can set the Destination directory of tFileCopy as:

"D:/file/"+ ((String)globalMap.get("tFileList_1_CURRENT_FILE"))

 

Please try and let me know if it works.

 

Regards

Shong

JohnRMK
Creator II
Creator II

Hello,

 

You can have two possible approaches, one simple and one more complex.

 

The first is to read all the files and use the global variables to execute files copy.

You can for example recover the name of the file (apple.csv)

 

in the if trigger have

((((String) globalMap.get ("tFileList_1_CURRENT_FILE")). contains ("apple") #(if -order1)

((((String) globalMap.get ("tFileList_1_CURRENT_FILE")). contains ("yellow") #(if -order2)

 

then you can execute tFileCopy with the directory /Apple Or /yellow

 

 

0693p000008v7u4AAA.png

 

A second approach which seems to me more dynamic and which can be executed on an infinite name of possibility

0693p000008v7xwAAA.png

You must have a csv file (local) or fixed list (uses the tFixedFlowInput component) with key pair values of type sourcePattern - targetFolder

 

You read that and you send it to memory (tHashOutput)

 

The second step is to read all the files in the directory with tfileList, you use the tIterateToFlow component to transform into a flow and you send this in memory like the first.

 

0693p000008v7y1AAA.png

(Here i use a sample directory ! and i list all my file)

 

The third step is a join and existence test to define in which directory you should copy the files

0693p000008v7yGAAQ.png

(My file pattern was Preview)

 

You can find attached a job a disign for you.

 

don't hesitate to ask questions if you don't understand

 

You have to replace the values in the first component and the directory in tFileList and everything should work