Reputation:
I would like to implement something equivalent to the unix command 'rm foo*' using Java. Obviously, I want it to be multi platform. I know that this can be done using the FilenameFilter class and File.delete() method, but I was wondering if I can perform this simple operation in a less verbose way.
Thanks in advance.
Upvotes: 2
Views: 443
Reputation: 96444
Look in commons-io for org.apache.commons.io.filefilter.WildcardFileFilter.
for (File file : new File(".").listFiles(new WildcardFilter("foo*"))) {
file.delete();
}
Upvotes: 1