Skip to Content
Author's profile photo Evgeniy Kolmakov

Taking additional file from another folder using File sender adapter

Once ago I worked on the scenario where plain text file had to be taken along with additional file. The main problem was that the additional file was placed in different folder and had naming scheme non-correlating with main file’s name.

Now I would like to demonstrate an approach I used to implement that scenario.

Let’s consider we have the main file containing some transactional data (for scenario simplification I use plain text file) and also we have to pick up additional file with some aggregated data for further processing.

The main files have naming scheme like: data_YYYYMMdd.txt and additional files are placed in subfolders within the source folder with Year/Month hierarchy:



and so on.

So, for each of our source files we have to pick additional file using year and month extracted from main file’s name as basis for additional file location and name determination.

The main idea is to use OS script to copy additional file from its original folder to the folder where the main file is placed and rename it accordingly.

Unix OS script written using Bash:



cp $addsrcfile $adddstfile

This script extracts year and month from source file name, builds the path to additional file and copies that file to main file’s folder.

Key settings for File sender adapter look like:

I’ve placed file data_20170604.txt in the source folder and additional file 201706_totals.txt – to the subfolder: usr/sap/PK5/PI_DATA/Test/2017/06.

Result of processing in the File sender channel:

As we can see, main file is taken, then OS command is executed and after that additional file is picked up by adapter as attachment.

Approach is based on the observation that OS script is executed after picking the main file but before searching for additional file(s).

As the result, we have the message with our main file as payload and additional file as attachment.

Further we can use java mapping, for example, to build desired output payload.

Regards, Evgeniy.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Patrick Weber
      Patrick Weber

      Thanks for sharing, I wasn't aware that OS commands will get executed before additional files are read. I could have used this knowledge a few years back and am sure I will need it at some point in the future.

      Author's profile photo Evgeniy Kolmakov
      Evgeniy Kolmakov
      Blog Post Author

      Hi Patrick!

      Yes, neither was I 🙂 It was just the sudden observation while debugging one of my scenarios.

      Regards, Evgeniy.