Listing all files in a directory in Android

Let’s say we have a directory in device’s storage called “mydir” and there are files inside it. By using this snippet we can list all names of that files and folders:

String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/maktabamajaziya";
String downloadedbooks = "";
File directory = new File(path);
File[] files = directory.listFiles();
for (int i = 0; i < files.length; i++)
{
	downloadedbooks += files[i].getName() + "\n";
}

Now downloadedbooks string variable contains all files and folders name.

loading...

Leave a Reply

Your email address will not be published. Required fields are marked *