Extensions for java.io.File

combineSafe

fun File.combineSafe(relativePath: Path): File
fun File.combineSafe(relativePath: String): File

Append a relativePath safely that means that adding any extra .. path elements will not let access anything out of the reference directory (unless you have symbolic or hard links or multiple mount points)

normalizeAndRelativize

fun File.normalizeAndRelativize(): File

Remove all redundant . and .. path elements. Leading .. are also considered redundant.