1, problem,

Traverse all problem files in a directory

2. Code implementation

fun getRecoverTrashFile(path: String) { if (TextUtils.isEmpty(path)) return try { var file = File(path) if (file == null || ! file.exists()) { return } var files = file.listFiles() if (files == null || files.size <= 0) { return } for (i in files.indices) { if (files[i].isDirectory) { var path = files[i].absolutePath getRecoverTrashFile(path) } else { var file = files[i] addTrashFileByPath(file) } } } catch (e: Exception) { LogUtil.i(TAG, "has error") e.printStackTrace() } }Copy the code