简体   繁体   English

带有正则表达式的Apache VFS resolveFile

[英]Apache VFS resolveFile with regex

If I have a directory called temp with the following files: 如果我有一个名为temp的目录,其中包含以下文件:

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 . 但是,我实际上想要做的是get a_file1.jpga_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? 那么,有谁知道如何使用VFS解决基于正则表达式的一组文件?

You could use the findFiles method, with a FileFilterSelector . 您可以将findFiles方法与FileFilterSelector一起使用。

You'll need to create your own FileFilter that accept s the files that match your desired regex. 您需要创建自己的FileFilteraccept与所需正则表达式匹配的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM