Fast delete folder with over 30,000 images in Android

I need to delete a folder with over 30,000 images. I have a .nomedia file inside to prevent scanning all the time. Trying to delete all files, I have to check the file name for each file. If I skip this check, the ".nomedia" file will be deleted. If this happens before the images - this will lead to a big loss in performance. Any idea how to solve this?

UPDATE:

Does anyone know how to hide images from scanning without using .nomedia? I can save files with fake extensions, but I'm not sure if this works.

Update:

In fact, the test shows me this result: checking the name makes deletion 50% slower. The problem is not in the control code, but in the system scan folder: (

+6
source share
2 answers

My solution for the moment:

  • Rename the image folder.
  • Create a new folder for images with the .nomedia file inside.
  • Run the background thread to delete the old folder.

This method is not faster than the previous one, but allows the user to continue working immediately. Of course, with one presumption - the user must know about the removal and cleaning of the occupied space for some time is not completed.

+1
source

Are you sure the file name verification process takes a long time? To delete files, I think you will need a File object anyway. Having a File object already, what is the cost of doing the following?

 ".nomedia".equals(file.getName()); 

The cost of the actual deletion ( file.delete() ) should be an order of magnitude greater than the comparison of strings.

Have you measured the actual time it takes to verify file names?

0
source

Source: https://habr.com/ru/post/910971/


All Articles