Java Check Directory For Zip Files
I have the below code which checks to see if folder exists on the sdcard, I would like to add another if statement if the folder exists to check that there are zip files inside the
Solution 1:
Filef=newFile("folder");
FilenameFilterf2=newFilenameFilter() {
publicbooleanaccept(File dir, String filename) {
return filename.endsWith("zip");
}
};
if (f.list(f2).length > 0) {
// there's a zip file in there..
}
Try the above..
Solution 2:
Have you looked at FileNameFilter
?
File f = newFile("/mnt/sdcard/folder");
if(e.exist()){//file exist ??File[] matchingFiles = f.listFiles(newFilenameFilter() {
publicbooleanaccept(File dir, String name) {
return name.endsWith("zip");
}
});//list out files with zip at the end
}
Post a Comment for "Java Check Directory For Zip Files"