Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply filename patterns on PathMatchingResourcePatternResolver?

Tags:

java

spring

I'm loading resources from the file system as follows using wildcards:

Resource[] resources = new PathMatchingResourcePatternResolver()
    .getResources("/my/path/*.zip");

Question: how can I load only .zip files that NOT have an underscore _ in the filename? Is that possible using the wildcard patterns at all?

like image 468
membersound Avatar asked Dec 04 '25 10:12

membersound


1 Answers

PathMatchingResourcePatternResolver will use the AntPathMatcher by default, which (luckily) can do RegExp based wildcards, so you can use it like this:

Resource[] resources = new PathMatchingResourcePatternResolver()
     .getResources("/my/path/{filename:[^_]*.zip}");

[^_] - is a negated character range, which will match any character except for _, so [^_]*.zip will, in turn, match any filenames that end with .zip and do not have _ in their name.

like image 178
zeppelin Avatar answered Dec 06 '25 22:12

zeppelin