Skip to content

Instantly share code, notes, and snippets.

@mcatta
Created May 8, 2013 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcatta/5540707 to your computer and use it in GitHub Desktop.
Save mcatta/5540707 to your computer and use it in GitHub Desktop.
Java recursive delete dir
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment