apache-camel

How to rename a file while using "move" in URL in apache camel


I have an URL like url = "file:D:/inputFolder?move=D:/outputFolder". we are making this url dynamically. I want to rename the file while moving, So I made it something like this url = "file:D:/inputFolder?move=D:/outputFolder&fileName=abc.txt". But I think move and fileName do not work together, it is not renaming.

Is there any alternative to do it? Please remember I want with "move" only. I cannot use .setHeader(..) also.

Thanks,


Solution

  • Two possible ways to achieve your goal.

    1. Use both "consumer" and "producer"

    Using this way, you are free to control where and how your destination can be set and has great freedom to control filename with the use of a processor/bean.

        from("file:D:/inputFolder")
            .to("file:D:/outputFolder?fileName=abc.txt")
    
    1. Use "consumer" only

    Using this way, you are treating your work as source data control. This can be use when your file is going to move within same drive. The drawback is the filename rename pattern is limited (refer to camel file language)

        from("file:D:/inputFolder?move=${file:parent}/../outputFolder/abc.txt")