Reputation: 6435
This is my FilenameFilter
which should only allow directories and files ending with .docx
. Yet, for some reason it allows now every file no matter which ending or if its a directory or not. Once I remove || dir.isDirectory()
its working as expected.
new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.toLowerCase().endsWith(".docx") || dir.isDirectory()) {
return true;
}
return false;
}
})
What am I doing wrong, that it accepts every file?
Upvotes: 0
Views: 30
Reputation: 12440
dir
is always a directory, simple as that.
Parameters: dir - the directory in which the file was found. name - the name of the file.
What you probably meant was:
new File(dir, name).isDirectory()
Upvotes: 3