Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all files and folders in one folder on Android

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?

like image 754
brian Avatar asked Feb 18 '13 06:02

brian


People also ask

How do I delete a folder and all files?

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.

How do I delete all my folders at once?

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.

How do I delete everything from multiple folders?

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.


1 Answers

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();  } 
like image 52
duggu Avatar answered Sep 29 '22 02:09

duggu