I copy files from Android internal storage to USB drive, folder LOST.DIR always is created by system. How can I remove this folder programmatically
I use library libaums to handle communicate with USB I tried to delete this folder after copy but USB get error
private fun exportOnlyFilesToUsb(fileSystem: FileSystem, file: File) {
val root = fileSystem.rootDirectory
if (!file.isDirectory) {
root.search(file.name)?.delete()
val targetFile = root.createFile(file.name)
copyFile(file, targetFile)
return
}
file.listFiles()?.forEach {
exportOnlyFilesToUsb(fileSystem, it)
}
}
private fun copyFile(file: File, usbFile: UsbFile) {
if (file.isDirectory || usbFile.isDirectory) return
FileInputStream(file).use { input ->
UsbFileOutputStream(usbFile).use { output ->
input.copyTo(output)
}
}
}
// Then I delete
root.search(LOST_DIR)?.delete()