cancel
Showing results for 
Search instead for 
Did you mean: 

Process a same file to 2 different target directories based on the timestamp

former_member187447
Participant
0 Kudos

Hi Folks,

I have a scenario where in I need to pick up a file from a /src directory and send it to 2 different target directories based on the timestamp. The first target directory /dir1 should be receiving all the files but the second target directory /dir2 should be receiving the files which are placed on only sundays. so for example if the files are placed daily with their timestamps as FileName12012014.txt (Mondays File) ,  FileName12022014.txt (Tuesdays file)---------.......FileName12072014.txt (sundays file) then based on the datetstamp the file which are placed only on sundays should go to second target directory /dir2 and all the files including the ones placed on sunday should go to first target directory /dir1.

If I have to achieve this using shell script and use that in PI file channel can I do the following :

The Shell script checks /src directory for files with todays date and if the todays date is not Sunday then the file is put in /dir1 only. and if the date is today's date and sunday then file is put in /dir1 directory as well as /dir2 Directory. Now use the shell script .sh in 1st sender comm channel (in Run OS before message processing) and configure the /dir1 directory in the channel. Take another sender comm channel and configure /dir2 directory to pick up the sunday files.


Please let me know if this approach is correct, also suggest if there is any better approach.


Regards

Kalyan

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

you can use dynamic configuration to set the directory name during the mapping.

You can use a udf to find which day it is..

Refer to below thread for sample code.

java - How to determine day of week by passing specific date? - Stack Overflow

1) enable ASMA sender file adapter

2) read filename in the mapping and parse date then find the week of the day using above code

3) set the dynamic directory name in mapping

http://wiki.scn.sap.com/wiki/display/XI/Dynamic+file+name+and+directory+in+Receiver+File+Adapter+-+s...

Answers (0)