I have a folder with several hundred (up to ~6000) small files. I want to delete all files in that folder (or the whole folder) quickly. Preferably in O(1) time.
Is there a way to delete 开发者_JS百科a nonempty folder? Alternatively, is there a way to delete multiple files (specified by a wildcarded name) in one API call?
I know all about File.listFiles()
and File.delete()
; achieving this functionality per se is easy; I'm after the performance now.
Edit: maybe from C? I already have an NDK library in the project - is there an NDK-supported syscall to that effect?
As CommonsWare said, you won't be able to get around around the fact that deleting/de-referencing files takes time and that can't be circumvented, even using C with the NDK. Just throw it into a background task to free up the UI and hope for the best.
精彩评论