Kotlin – Delete Recursively

To delete a file/folder and its children in Kotlin, use extension function to java.io.File, File.deleteRecursively().


The function returns true if the operation is successful, else false. Any error during the operation could result in partial deletion of the file children.


Following is an example to demonstrate the usage of deleteRecursively() :

Kotlin Delete Recursively

All the files and folders inside folderA shall be deleted.