I use this code to delete all files:
File root = new File("root path"); File[] Files = root.listFiles(); if(Files != null) { int j; for(j = 0; j < Files.length; j++) { System.out.println(Files[j].getAbsolutePath()); System.out.println(Files[j].delete()); } }
It will delete false where Files[j]
is a folder.
I want to delete folder and all its sub files.
How can I modify this?
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.
To delete multiple files and/or folders: Select the items you'd like to delete by pressing and holding the Shift or Command key and clicking next to each file/folder name. Press Shift to select everything between the first and last item.
You can delete multiple files or folders by holding down the Ctrl key and clicking each file or folder before pressing Delete . You can hold down the Shift key while pressing the Delete key to prevent files from going to the Recycle Bin when deleted.
Check this link also Delete folder from internal storage in android?.
void deleteRecursive(File fileOrDirectory) { if (fileOrDirectory.isDirectory()) for (File child : fileOrDirectory.listFiles()) deleteRecursive(child); fileOrDirectory.delete(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With