You can solve this problem recursively, starting from the root directory of the external memory / SD card.
Incorrect code from my head (method names may be incorrect)
public File findFile(File dir, String name) {
File[] children = dir.listFiles();
for(File child : children) {
if(child.isDirectory()) {
File found = findFile(child, name);
if(found != null) return found;
} else {
if(name.equals(child.getName())) return child;
}
}
return null;
}
If you want to find all occurrences of this name on your SD card, you will have to use the List to collect and return all matches found.
source
share