Lisa
Lisa

Reputation: 53

How to get File Name without extension in Camel

Hi Does anyone know how to get a file name without extension in camel. using spring xml.

I know ${header.CamelFileNameOnly} will give the full file name like "test.txt".

I would just like to get the name "test" and need to use this name in somewhere else, does anyone know how to do it ?

Upvotes: 4

Views: 10690

Answers (2)

Hussain Pirosha
Hussain Pirosha

Reputation: 1376

Use the file-expression language. Your route shall be something like

<camel:route>
    <camel:from uri="file://input/orders" />
    <camel:setHeader headerName="FileNameWithoutExtension">
        <camel:simple>${file:onlyname.noext}</camel:simple>
    </camel:setHeader>
</camel:route>

Upvotes: 8

Claus Ibsen
Claus Ibsen

Reputation: 55525

See the Camel documentation

You can then do use simple language (http://camel.apache.org/simple.html) to grab the only the name part using ${file:onlyname.noext}

Upvotes: 5

Related Questions