Reputation: 14565
I'm trying to delete my files folder from Internal Storage, but the code which I'm using is not actually working. Any ideas why?
Button login = (Button) findViewById(R.id.login_btn);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = "/data/data/"+context.getPackageName()+"/files/";
Log.e("","path : "+name);
File myDir = new File(name);
myDir.delete();
boolean iff = myDir.delete();
Log.e("","iff : "+iff);
}
});
The result which I get after button click :
11-17 13:09:58.869: E/(15952): path : /data/data/com.android.test/files/
11-17 13:09:58.869: E/(15952): iff : false
Upvotes: 1
Views: 6634
Reputation: 3597
File.delete() will only delete empty directories. You will need to (recursively) delete the directory's contents first. That has been answered here. (Since that's an SO answer I'm not copying and pasting that answer to here)
Upvotes: 4
Reputation: 3913
You are deleting the file twice and only checking the return value of the second delete.
If a file does not exist and you call delete() on it you get "false" as result (file was not deleted because it did not exist).
Upvotes: 7