0

Possible Duplicate:
How to delete entire contents of sdcard programmatically in Android 2.2

I want to clear all the files from android device programmatically.

Can anyone suggest me the way or code, Hence I can perform this operation please...

Thanks in advance.

Community
  • 1
  • 1
Bharat Godhani
  • 110
  • 4
  • 12

1 Answers1

4
public static boolean deleteDirectory(File path) {
        // TODO Auto-generated method stub
        if( path.exists() ) {
            File[] files = path.listFiles();
            for(int i=0; i<files.length; i++) {
                if(files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                }
                else {
                    files[i].delete();
                }
            }
        }
        return(path.delete());
    }

add the code just call it when ever you require using the path of the directory to delete or the file to delete

Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
  • 1
    If you copy-paste from an [external source](http://www.developerfeed.com/io/snippet/how-recursively-delete-file-directory), you might as well add a reference to it. – MH. Apr 28 '12 at 07:23
  • @MH might have been copied long back but it was the code of project which i was using so just pasted it – Shankar Agarwal Apr 28 '12 at 07:25