aboutsummaryrefslogtreecommitdiff
path: root/src/Utilities/Path.kt
blob: fea222501a758fda17bb253f29b67f885ee0df1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package org.jetbrains.dokka

import java.io.*

fun File.getRelativePath(name: File): File {
    val parent = parentFile ?: throw IOException("No common directory")

    val basePath = getCanonicalPath() + File.separator;
    val targetPath = name.getCanonicalPath();

    if (targetPath.startsWith(basePath)) {
        return File(targetPath.substring(basePath.length()))
    } else {
        return File(".." + File.separator + parent.getRelativePath(name))
    }
}

fun File.appendExtension(extension: String) = if (extension.isEmpty()) this else File(getPath() + "." + extension)