public void deleteDirectory(View view) {
File download = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"Download");;
if(download.exists()) {
Log.i("TAG",""+download.exists());
Log.i("TAG",download.getAbsolutePath());
File[] files = download.listFiles();
Log.i("TAG",""+files.length);
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {
File Dir = new File(files[i].getAbsolutePath());
File[] filesInDir = Dir.listFiles();
//Elimina archivos de directorio.
for(int j = 0; j < filesInDir.length; j++){
Log.i("TAG", "Elmina en dir " + filesInDir[j]);
filesInDir[j].delete();
}
}
else {
//Elimina archivo.
Log.i("TAG", "Elmina archivo " + files[i]);
files[i].delete();
}
}
}
}
I need to delete all the files that are in the Android download folder, but it does not show more than the log of the permission to read, in addition to a warning that says "File.delete() is ignore"
Regarding the message:
It is not an error, it is simply a message since the method
.delete()
returns a boolean type value that determines whether or not it could delete the file, in this case you are not assigning it to a variable, you are not using it for this reason the IDE will tell you indicates that the value will be ignored.Check out:
How to delete a file in Android Studio? How to delete a file in Android Studio?
To delete the files inside a directory I suggest you first use this method to get the path of the external storage directory, even check if it is mounted:
Now you use the previous method to get the directory and in this way you would delete the files:
Remember that it is too important to define the permission
WRITE_EXTERNAL_STORAGE
on your fileAndroidManifest.xml
and request the manual request of the permissions:WRITE_EXTERNAL_STORAGE permission request