I have the code below that checks if a folder exists on the SD card, I would like to add another if statement if the folder exists to check if there are zip files in the folder if it really exists. What can I do to check the folder for the zip extension. There should be a lot of zip codes in the folder, but I want it to be checked to make sure there are zip files and there is no other file extension. I thank you for any help with this.
File z = new File("/mnt/sdcard/folder");
if(!z.exists()) {
Toast.makeText(MainMethod.this, "/sdcard/folder Not Found!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainMethod.this, "/sdcard/folder Found!", Toast.LENGTH_LONG).show();
}
EDIT:
Thanks guys for the help, that’s what I ended up using with your help, I haven’t tested it yet, but I feel good.
File z = new File("/mnt/sdcard/Folder");
if(!z.exists()) {
} else {
FilenameFilter f2 = new FilenameFilter() {
public boolean accept(File dir, String filename) {
return filename.endsWith("zip");
}
};
if (z.list(f2).length > 0) {
} else {
}
}
source
share