0

I am accessing the assets folder of installed applications from my application. I am able to access the assets folder of every installed application but it returns me with some folder & some files. If it returns me only files then there is no problem I am able to access those files but how could I come to know that is this the file or folder which is I am accessing?

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
AndroidDev
  • 189
  • 1
  • 2
  • 7

1 Answers1

0

If you want to check if it's a file/directory then you could do something like this:

File file = new File(filepath);
 if(file.isDirectory())
 {
     //Do something if it's a directory
 }
 else 
 {
     //Do something else if it's a file
 }

If you want to check all the files in a directory you can do:

File path = new File("/mnt/sdcard/something");
if( path.exists() ) {
    File[] files = path.listFiles();
    if (files == null) {
        //Break
    }
    for(int i = 0; i < files.length; i++) {
         if(files[i].isDirectory()) {
              //Logic if directory
         }
          else {
          //Logic if file
        }
   }

If you want to know if a filepath contains a word of some installed file then you can check:

if(filepath.contains(stringToLookFor))
{
//Logic if file contains part of the string
}