How to get list of files inside a directory in android


public static String[] getListOfFilesInDirectory(String directory) {
 String filesPath[] = null;
 Vector<String> vector = new Vector<String>();

if (directory != null) {
 try {
 File f = new File(directory);
 if (f.isDirectory()) {
 File files[] = f.listFiles();
 if (files != null) {
 int len = files.length;
 if (len > 0) {
 for (int i = 0; i < len; i++) {
 if (files[i] != null) {
 if (!files[i].isDirectory()) {
 if (files[i].isFile()) {
 String filePath = null;
 try {
 filePath = files[i]
 .getAbsolutePath()
 .toString();
 } catch (Exception e) {
 e.printStackTrace();
 }

if (filePath != null) {
 if (!filePath.equals("")) {
 vector.add(filePath);
 }
 }

}
 }
 }
 }
 }
 }
 }
 } catch (Exception e) {
 e.printStackTrace();
 }

if (vector.size() > 0) {
 filesPath = new String[vector.size()];
 vector.toArray(filesPath);
 }
 }

return filesPath;
 }

Advertisements

Tags: ,

About krishjlk

http://www.facebook.com/krishna.kanth.121

One response to “How to get list of files inside a directory in android”

  1. mail says :

    Enter your comment here…;…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: