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

import java.io.*

fun File.getRelativePath(name: File): File {
    val parent = getParentFile()

    if (parent == null)
        throw IOException("No common directory");

    val basePath = getCanonicalPath();
    val targetPath = name.getCanonicalPath();

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

fun File.appendExtension(extension: String) = File(getPath() + "." + extension)