Never use / sdcard / path. It is not guaranteed to work all the time.
Use the code below to get the path to the sdcard directory.
File root = Environment.getExternalStorageDirectory(); String rootPath= root.getPath();
In the rootPath field, you can create the path to any file on the SD card. For example, if there is an image in /DCIM/Camera/a.jpg, then rootPath + "/DCIM/Camera/a.jpg" will be the absolute path.
However, to list all the files in sdcard, you can use the code below
String listOfFileNames[] = root.list(YOUR_FILTER);
listOfFileNames will have the names of all the files that are present on the SD card and pass the criteria set by the filter.
Suppose you want to list only mp3 files, then pass the filter class name below to the list () function.
FilenameFilter mp3Filter = new FilenameFilter() { File f; public boolean accept(File dir, String name) { if(name.endsWith(".mp3")){ return true; } f = new File(dir.getAbsolutePath()+"/"+name); return f.isDirectory(); } };
Shash
source share