views:

924

answers:

2

How do I check if a directory exist on the sdcard in android?

+5  A: 

Regular Java file IO:

File f = new File(Environment.getExternalStorageDirectory() + "/somedir");
if(f.isDirectory()) {
   ....

Might also want to check f.exists(), because if it exists, and isDirectory() returns false, you'll have a problem. There's also isReadable()...

Check here for more methods you might find useful.

synic
My error just turned out to be a lacking directory in my path, but thanks. I began to wonder if android's filesystem didn't support normal methods like this :-P
Alxandr
+3  A: 
File dir = new File(Environment.getExternalStorageDirectory() + "/mydirectory");
if(dir.exists() && dir.isDirectory()) {
    // do something here
}
mbaird