private fun getAllFiles(root: File, endName: Array<String>): List<FileBean> { try { val files = root.listFiles() if (files != null) { for (f in files) { if (f.isDirectory) { if (f.absolutePath != root.absolutePath) getAllFiles(f, endName) } else { for (i in endName.indices) { if (f.name.endsWith(endName[i])) { val fileName = f.name val fPath = f.absolutePath val fileLength = f.length() val fileBean = FileBean(fileName, fPath, fileLength) Log.i("MediaStoreUtil", "====检索的文件的====" + fileName) fileLists.add(fileBean) } } } } } } catch (e: Exception) { } return fileLists }
getAllFiles(Environment.getExternalStorageDirectory(), arrayOf(".xls"))