Skip to content

Instantly share code, notes, and snippets.

@vorobeij
Created April 12, 2023 21:19
Show Gist options
  • Save vorobeij/5ec6db4d7b8d4492bd4d54972f9fd439 to your computer and use it in GitHub Desktop.
Save vorobeij/5ec6db4d7b8d4492bd4d54972f9fd439 to your computer and use it in GitHub Desktop.
scan Documents on device
/** List of extension file paths */
override fun scan(folders: List<Uri>, extensions: Regex): List<DocumentFile> {
val result = mutableListOf<DocumentFile>()
fun scan(root: DocumentFile?, extensions: Regex, outputUris: MutableList<DocumentFile>) {
if (root == null) return
val name = root.name
if (root.isFile && name != null && name.contains(extensions)) {
outputUris.add(root)
return
}
if (root.isDirectory) {
root.listFiles().forEach {
scan(it, extensions, outputUris)
}
}
}
// scan file tree
folders.forEach { uri ->
scan(DocumentFile.fromTreeUri(context, uri), extensions, result)
}
logd(result.map { it.uri }, "video files")
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment