membersound
membersound

Reputation: 86905

How to get number of resources in directory in spring?

@Value("file:" + "${d:/my/dir/}")
private Resource dir;

How can I get the number of files in that resource dir? Unfortunately the Resource interfaces does not offer any getFiles() method...

Upvotes: 0

Views: 64

Answers (1)

Joeblade
Joeblade

Reputation: 1743

Based on this version of the Resource interface, you can call getFile

File theDir = dir.getFile();
if (theDir.isDirectory()) {
    theDir.list();
}

if you combine this with the propertyplaceholderconfigurer you might get what you're lookign for:

Upvotes: 1

Related Questions