cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to remove file extension

Former Member
0 Kudos

Hi all

I have a scenario where my sender file adapter should pick up multiple files with different extensions and my receiver file adapter creates the same files but without extension

can anyone provide me the udf for the logic

-keerthi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You can use DynamicConfiguration method to rename the file. [Refer Michal's blog |http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/2664] [original link is broken];to do some required ASMA settings in Sender & Receiver file adapter and then use below mentioned UDF code to solve your problem.

DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

String source_file = conf.get(key);

//Below line of code will remove the file extention from the file name
String target_file = source_file.substring(0, source_file.length() - 4)

conf.put(key, target_file);

return "";

Former Member
0 Kudos

Beware of the following line :

String target_file = source_file.substring(0, source_file.length() - 4)

it is not leakproof, as it statically assumes that file extension is 4 chars ("." + 3 chars, like on windows) ...

Rgds

Chris

Former Member
0 Kudos

> it is not leakproof, as it statically assumes that file extension is 4 chars ("." + 3 chars, like on windows) ...

Thanks Chris for pointing this out.. Yes this is not leakproof so one has to change this line of code according to his/her need.

Answers (2)

Answers (2)

Former Member
0 Kudos

HI Keerthika,

Keep the source directory filename as ., so that it would pick all the files placed in the source directory.

Use the below UDF, to create the target file name

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create(u201Chttp://sap.com/xi/XI/System/Fileu201D,u201CFileNameu201D);

String MyFileName = "";

conf.put(key, myFileName);

And in the Adapter specific message attributes in receiver communication channel select the option Filename.

Thanks,

Former Member
0 Kudos

Are you using ASMA..

If you need to pick files with multiple extensions u can mention the same in the sender file adapter by selecting advanced selection for file picking and ther you give all the extensions for example same .txt,.pdfand etc..by mentioning the same folder path.

And in receiver adapater just mention the file name.

Regards,

Sainath chutke