How to reorganize file with kotlin

I want to list -> extract -> reorganize -> compress

Here is what I was tried. I want to know what should I use to do this.

@ExperimentalPathApi
fun CoroutineScope.readInputs(): Flow<Path> = inputDir.listDirectoryEntries("*.rar").asFlow()

@ExperimentalPathApi
fun CoroutineScope.extract(upstream: Flow<Path>) = channelFlow {
    upstream.collect { path ->
        val targetDir = tempDir / path.nameWithoutExtension
        path.extract(targetDir).execute()
        send(targetDir)
    }
}
1 Like