Home > Net >  How to remove LOST.DIR folder from USB Mass Storage in Android programmatically
How to remove LOST.DIR folder from USB Mass Storage in Android programmatically

Time:02-10

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()

CodePudding user response:

LOST.DIR is a folder created by an Android phone on the SD card to get back accidentally deleted files like photos, videos, etc. If you are a smartphone user, you would have already seen LOST.DIR folders are located on your external SD card.

Lost.DIR folder basically helps you to recover files lost due to various reasons like application crash, improper ejection of the USB drive or SD card/ ejection of SD card during the reading/ writing process, Android abruptly frozen or shut down unexpectedly, interruptions while downloading files on SD card, etc.

Some users might delete Lost.DIR folder thinking that it is a virus folder, which is completely false. You might have observed that once you delete Lost.DIR folder, again it will be automatically recreated after you boot your phone, this is because LOST.DIR is the Android system folder.

So don't delete this. Actually, you can't do that.

  •  Tags:  
  • Related