libaums icon indicating copy to clipboard operation
libaums copied to clipboard

Deleting multiple files is slow

Open petrs143 opened this issue 5 years ago • 5 comments

Hello, when I delete 2500 files in one folder, on some devices, it takes more than 30 minutes. In my opinion it is caused by calling write() on each delete(). I' ve already tried to call only removeEntry() on each file and then call write(), but it corrupts my drive somehow and deletes more files than should delete. Is there any solution?

petrs143 avatar May 24 '20 21:05 petrs143

In theory this should be possible. Can you show some code?

magnusja avatar May 24 '20 22:05 magnusja

In FatDirectory:

  fun deleteFiles(files: List<FatFile>) {
        files.forEach {
            it.initChain()
            removeEntry(it.entry)
        }
        write()
        files.forEach {
            it.chain.length = 0
        }
    }

Usage:

val files = folder.listFiles().toList()
folder.deleteFiles(files.filter { /* Some filtration by name */ })

petrs143 avatar May 25 '20 12:05 petrs143

Does it work if you do not set the chain to 0?

magnusja avatar May 25 '20 13:05 magnusja

No, it still deletes more files than it should (all files in folder)

petrs143 avatar May 25 '20 13:05 petrs143

@magnusja I've noticed that FatFile.delete() doesn't work for me too. But only for 400+ files in a folder.

My usage

  • Create a folder with 400 files on a PC
  • In my app, I list the folder and delete 200 files (like the previous usage)

But when I open USB drive on a PC whole folder disappear and remaining files are in LOST.DIR folder.

petrs143 avatar Jun 12 '20 09:06 petrs143