Created
May 8, 2013 14:12
-
-
Save mcatta/5540707 to your computer and use it in GitHub Desktop.
Java recursive delete dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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