Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android, how to get directory listing?

Tags:

java

android

Just a quick question, how to I get a list of directories inside a specified directory.

for example,

String path = Environment.getExternalStorageDirectory().toString()+"/myApp/"; 

now I'd need to get the list of directories that are inside the "path" directory.

Thanks!

like image 394
Roger Avatar asked Aug 09 '11 14:08

Roger


People also ask

How do I get a list of folders in Android?

File myDirectory = new File("path to some directory"); File[] directories = myDirectory. listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname. isDirectory(); } });

What is a directory Android?

android.provider.ContactsContract.Directory. A Directory represents a contacts corpus, e.g. Local contacts, Google Apps Global Address List or Corporate Global Address List. A Directory is implemented as a content provider with its unique authority and the same API as the main Contacts Provider.


1 Answers

Something like that (add null checking, exceptions etc..)

File f = new File(path); File[] files = f.listFiles(); for (File inFile : files) {     if (inFile.isDirectory()) {         // is directory     } } 
like image 66
MByD Avatar answered Sep 25 '22 04:09

MByD