Skip to content

Instantly share code, notes, and snippets.

@Antarix
Last active November 24, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Antarix/3878682 to your computer and use it in GitHub Desktop.
Save Antarix/3878682 to your computer and use it in GitHub Desktop.
Create Directories on Android SdCard. Simply pass the url as a parameter e.g "/myfolder/newFolder"
public void createDirectories(String url) {
Log.d("DIRECTORY CHECK", "Checking directory " + url + " exist or not");
File SDCardRoot = new File(Environment.getExternalStorageDirectory()
.toString() + url);
if (!SDCardRoot.exists()) {
Log.d("DIRECTORY CHECK",
"Directory doesnt exist creating directory "
+ Environment.getExternalStorageDirectory()
.toString());
boolean outcome = SDCardRoot.mkdirs();
Log.d("DIRECTORY CHECK",
"outcome for " + SDCardRoot.getAbsolutePath() + " "
+ outcome);
}
Log.d("DIRECTORY CHECK", "Directory created successfully!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment