android sdcard - Get path of Specific file from SD Card -


i know there lots of questions , answers discussing question not finding proper answer it.

i have file in sdcard name database.db. want path of file. file stored @ mnt/sdcard/db/database.db. need output mnt/sdcard/db/ please me code or example appreciated

i have filename possible path it?

edit again ^-^:

i think understood want do: having filename input, want search whole sd card it, , if present, want obtain path of directory in in.

bear in mind full search file might slow if user's sd-card contains lot of folders , files.

here simple function search file:

public static void findfilepath(file dir, string filename, list<string> result) {      // files in dir     file[] files = dir.listfiles();     for( file f : files ){         if( f.isdirectory() ){             // recurse             findfilepath(dir, filename, result);         }          else{             if( f.getname().equals("filename") ){                 string abspath = f.getabsolutepath();                 result.add(abspath.substring(0, abspath.lastindexof(file.separator)));             }         }     } } 

and here usage:

list<string> result = new arraylist<string>(); findfilepath( environment.getexternalstoragedirectory(), "database.db", result);  system.out.println(result.get(0)); 

now, have couple of possible issues:

  1. there might more once directory contains file searching
  2. the search arbitrarily slow if file system not indexed (which don't think is), , if number of files , directories big.

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -