In order to remove a directory within Android internal storage, this is the kind of code I use.
val directory = getDir("myDirName", MODE_PRIVATE) // *1.
if (directory.isDirectory()) {
directory.delete()
}
The first problem is that line *1 will create the directory in case it does not exist.
Is there a way to actually know if a directory exists or not, without creating one if it does not?
Beside, I also noticed that this code is not working one hundred percent of the time.
Is there a better way to remove a directory?
You could implement something like that: