Hi there! Is there any way to delete a directory t...
# io
m
Hi there! Is there any way to delete a directory that might not be empty?
FileSystem::delete
does not work for that, as documented.
f
Hi! Unfortunately no, at the moment there is no way to do that as directory listing is not yet supported (https://github.com/Kotlin/kotlinx-io/issues/222). It will be addressed as part of https://github.com/Kotlin/kotlinx-io/issues/241 in the near future.
gratitude thank you 1
m
According to these release notes https://github.com/Kotlin/kotlinx-io/releases/tag/0.3.4 the directory listing function is now supported.
🙌 1
z
Copy code
fun FileSystem.deleteRecursively(path: Path, mustExist: Boolean = true) {
    if (metadataOrNull(path)?.isDirectory == true) {
        list(path).forEach {
            deleteRecursively(it, false)
        }
    }
    delete(path, mustExist)
}
👌 1
m
Indeed! Thank you for the heads up.