Created
April 12, 2023 21:19
-
-
Save vorobeij/5ec6db4d7b8d4492bd4d54972f9fd439 to your computer and use it in GitHub Desktop.
scan Documents on device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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