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
2010-04-12 21:05:51
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
2010-04-12 21:58:00
+3
A:
File dir = new File(Environment.getExternalStorageDirectory() + "/mydirectory");
if(dir.exists() && dir.isDirectory()) {
// do something here
}
mbaird
2010-04-12 21:07:49