Kotlin: Copy Directory Recursively Including Dot Files

Here’s the way to copy directory recursively including dot files in Kotlin. I wanted do that with command but I couldn’t. So I used Kotlin.


  • Kotlin 1.1.2

Code to Copy Directory

I used java.io.File, so it is intrinsically the same as in Java.


Second argument of copyRecursively method defines to not to override when the file exists at the copy destination.

Copy All Files and Directories in the Directory

The first argiment copyRecursively receives is complicated, but it’s for the case when d is defined with relative path.