Search code examples
javaapache-commons-vfs

Apache VFS resolveFile with regex


If I have a directory called temp with the following files:

a_file1.jpg
a_file2.jpg
b_file1.jpg
b_file2.jpg

It's possible to get all files like this:

VFS.getManager().resolveFile("temp").getChildren();

But, what I actually want to do is get a_file1.jpg and a_file2.jpg. Maybe like:

VFS.getManager().resolveFile("temp/a*").getChildren();

But this throws an exception:

org.apache.commons.vfs.FileSystemException: Could not list the contents of "temp/a*" because it is not a folder.

So, does anyone know how to resolve a set of files based on a regex with VFS?


Solution

  • You could use the findFiles method, with a FileFilterSelector.

    You'll need to create your own FileFilter that accepts the files that match your desired regex.