AlgorithmFromHell
AlgorithmFromHell

Reputation: 370

Camel from smb - combining "delete=true" and filtering by filename

I need to convert files from extension A to B matching only a specific filename, The file with the original extension should be deleted on processing. However, other files in the directory should not be deleted. I am using Apache Camel 2.17.2 (and unfortunately cannot upgrade to newer version).

I have tried to combine the delete=true flag along with file filters, but it deletes all files, even though the filter works.

from("smb://myDirectory?delete=true&password=xxxxxx&username=zzzz"). .filter(PredicateBuilder.and(header(Exchange.FILE_NAME).startsWith("Report"), PredicateBuilder.not(header(Exchange.FILE_NAME).endsWith("zip"))))

This solution first converts the original files to my desired format, does not convert the converted file again - as expected - but then it also deletes the converted file because of the delete=true flag which as I understand has precedence over the filter.

I have also tried putting all this in the route parameters:

from("smb://myDirectory?delete=true&fileName=Report*.csv&password=xxxxxx&username=zzzz")

But then the regex does not match - I cannot understand why - and besides I think the problem may be the same even if I could get the regex to work. The filename example is Report_Financial_20190201.csv.

The only thing I can think of now is a .choice().when() condition, which would check the filename and extension and either convert it or not and put it in the target folder... which potentially results in an endless loop and generally seems like an awful hack.

What's the suggested approach to the problem? Note: I cannot use a temp folder or anything like this due to requirements restrictions.

Upvotes: 0

Views: 831

Answers (1)

AlgorithmFromHell
AlgorithmFromHell

Reputation: 370

Indeed these flags can be combined. I just needed to use the include option instead of filename. This answer helped me: HOW: Apache Camel, Regex match files My endpoint now looks like this:

from("smb://myDirectory?delete=true&include=Report.*\\.csv&password=xxxxxx&username=zzzz")

Upvotes: 1

Related Questions