Reputation: 253
I need to get the all files irrespective for its file name using spring ResourcePatternResolver.
I have already tried with following code
private static final String BPMN_PATH = "process";
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
Resource[] resource = resourcePatternResolver.getResources("classpath:" + BPMN_PATH + "**/*.bpmn");
But this is only if the file lists are in the classpath(project directory).
In my scenario the files are located in system directory. For this I have tried with following code
private static final String BPMN_PATH = System.getProperty("user.home");
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
Resource[] resource = resourcePatternResolver.getResources("file:" + BPMN_PATH + File.separator +"process.bpmn");
But this will work only for the specified file (process.bpmn).
Can anyone please help on this?
Upvotes: 4
Views: 11606
Reputation: 115
Check the Spring Framework PathMatchingResourcePatternResolver.
/WEB-INF/*-context.xml
com/mycompany/**/applicationContext.xml
file:C:/some/path/*-context.xml
classpath:com/mycompany/**/applicationContext.xml
Upvotes: 1
Reputation: 90497
Well I remember the ant-style wildcard pattern should also work for file:
.
To load all files in a folder (e.g. /foo/bar/
) , you could use :
resourcePatternResolver.getResources("file:/foo/bar/*");
Please note that it is only limited to the files included in this folder . It will not include the file inside its sub-folders.
If you want to recursively load all files , even the files in each sub-folders and sub-sub-folder and etc., you could use:
resourcePatternResolver.getResources("file:/foo/bar/**");
Upvotes: 1