Desenfoque
Desenfoque

Reputation: 816

Camel: GenericFileFilter and Recursive not working together

I'm trying to download several files from a FTP server using camel.

I'm using the recursive=true option and include=..xlsx|..xlsm option.

My endpoint looks like this:

from(FTP_OPTION + "?include=.*.xlsx|.*.xlsm&recursive=true")
.to(ANOTHER_ENDPOINT);

this works ok, but now I need a more powerful filter so I'm using a GenericFileFilter

My filter looks like this:

public class MyFilter <T> implements GenericFileFilter<T>{
    @Override
    public boolean accept(GenericFile<T> file) {    
        String name = file.getFileName();
        final String regex = "[\\w,\\s-ñÑ]+\\.(xlsx|xlsm)";
        return name.matches(regex);
    }
}

and my new endpoint is this:

from(FTP_OPTION + "?filter=#myFilter&recursive=true")
.to(ANOTHER_ENDPOINT);

The problem is when I use this endpoint, only takes the files from the root level and do not looks for files in the subdirectories.

Is there some kind of incompatibility between Filter and Recursive? Or I'm missing some other option?

Thanks!

Upvotes: 1

Views: 998

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55540

AFAIR the generic filter is also used for the directories, so you need to check for this and return true for which directories to accept. There is a isDirectory method you can use to know, and if you just want all dirs, then return true.

Upvotes: 1

Related Questions