Filter all files in any depth by file prefix inside a directory

370 Views Asked by At

I'm using Apache Commons VFS2.0 to access files both in a local file system and a remote file system. I'm trying to find a way to filter all the descendent files in any depth with FileType=File and has a given filePrefix with the file name. I was able to do it for the same case except for file prefix, but for file extension, as follows.

FileSelector fileSelector = new FileExtensionSelector("extensions...");
directory.findFiles(fileSelector);

In this way, I was able to fetch all the files(no folders) in any depth with the given extension. I have tried the below approach but it only works for matching files with depth=1.

FileFilterSelector prefixFileSelector = new FileFilterSelector(new PrefixFileFilter("Prefix"));
directory.findFiles(prefixFileSelector);

Appreciate if anyone can give a suggestion.

1

There are 1 best solutions below

0
vladkabat On
new FileFilterSelector(fileFilter) {
    @Override
    public boolean traverseDescendents(FileSelectInfo fileInfo) {
        return true;
    }

    @Override
    public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
        return accept(fileInfo);
    }
}