splitting filename

I have a filename assad.txt. I want to split into 2 parts and map the two parts to 2 different variables.

i want it to be like assad as filename and ext as file extension.

Can anyone please suggest me how to do that?

If you will only ever have just the filename then you can use pub.string:tokenize.

If you might have a full path sometimes, write a Java service that uses java.io.File methods (e.g. getName()) to get the filename part and then use String.split() to break apart the base name and extension.

Thanks for ur help reamon. well now my problem is that the filenames comes from a list. they are attachment names.

In a message there can be multiple attachments. Now its splitting only one file.

How do i do so for the other files?

thanks for ur help :slight_smile:

Loop over the list perhaps creating a document list where each entry has 2 fields, baseName and extension.

thanks for ur reply reamon.

my problem is that, the filenames are in an input canonical, am using a transformer to split it. how do i loop on a variable which is on the canonical?

Within the IS document you presumably have a list of filenames. Loop over the list (refer to the docs for looping over a list that is within a document). For example, you might loop over \yourDoc\header\filenames with an output list of myFilenameList.

Then use the transformer within the loop to split each entry. You’d map from \yourDoc\header\filenames (which will appear to be a single string within the loop, rather than a list) to the transformer input. And map the transform output, say it outputs basename and extension, to fields within your myFilenameList var (which will appear to be a single document within the loop rather than a document list).

reamon, thank you for your reply. i am still some trouble with that. when i try to make a loop over the list (the variable that appears is attachment[0]/filename), and the loop just does not work on it. i understand its cause of the variable name, but how will i make it loop on a list like this?

Based on the var name it looks like you have a list of documents rather than a string list. Loop over the attachment list. Then within the loop map from attachment/filname to the input of the transformer.