I am trying to make an algorithm to scan all files in android but I am facing issues in adding directories to an array can anyone tell me why I am facing this issue?
The code I have currently written:
private fun getFiles() {
val mainDirectory = File(“storage/emulated/0/”)
val files = mainDirectory.listFiles()
val fileDirectories = Array(999){File(“”)}
var count = 0
if (files != null) {
for (file in files) {
if (file.name.endsWith(“.mp3”) ||
file.name.endsWith(“.MP3”) ||
file.name.endsWith(“.M4A”) ||
file.name.endsWith(“.m4a”) ||
file.name.endsWith(“.AAC”) ||
file.name.endsWith(“.aac”)) {
databaseHandler.addSong(file.name, file.path, file.toURI())
} else if (file.isDirectory) {
fileDirectories[count] = file
count++
}
}
}
}