1
String fldr= "Main";

I need to find whether there is a folder called fldr in anywhere in the directory.

This will return the Directory of External storage

String SDpath = Environment.getExternalStorageDirectory().toString();

If there is a folder similar to fldr I need to get its directory and check whether its writable.. How to do it ?

GreenCodes
  • 241
  • 1
  • 4
  • 11

1 Answers1

3

do this way,

File dir = new File(Environment.getExternalStorageDirectory() + "/Main");
if(dir.exists() && dir.isDirectory()) {
    // do something here
}

/**
   * @return True if the external storage is available.
   * False otherwise.
   */
  public static boolean checkAvailable() {

    // Retrieving the external storage state
    String state = Environment.getExternalStorageState();

    // Check if available
    if (Environment.MEDIA_MOUNTED.equals(state)
        || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      return true;
    }

    return false;
  }

  /**
   * @return True if the external storage is writable.
   * False otherwise.
   */
  public static boolean checkWritable() {

    // Retrieving the external storage state
    String state = Environment.getExternalStorageState();

    // Check if writable
    if (Environment.MEDIA_MOUNTED.equals(state)) {
      return true;
    }

    return false;

  }
Jignesh Jain
  • 1,518
  • 12
  • 28
  • Thanks for your help. But in this case we don't know "Environment.getExternalStorageDirectory() + "/Main" exists. It may be a something like this "Environment.getExternalStorageDirectory() +"folder1"+ "/Main"" then how to find whether main is exists ? – GreenCodes Apr 29 '15 at 10:49
  • you just pass only directory name(folder name). – Jignesh Jain Apr 29 '15 at 10:50
  • when use File directory = new File("DCIM"); it says it does not exists – GreenCodes Apr 29 '15 at 11:23
  • but when use File dir = new File(Environment.getExternalStorageDirectory() + "/DCIM"); it says it exists.. so how can I get correct results only using "DCIM" – GreenCodes Apr 29 '15 at 11:24