diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/File.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/File.kt index 02a302e4..2ccb74f6 100644 --- a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/File.kt +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/File.kt @@ -13,6 +13,8 @@ expect class File(path: String) { val fileExtension: String + val parent: File? + fun mkdirs(): Boolean diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/File.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/File.kt index 4c9c8b43..f10c2f25 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/File.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/File.kt @@ -1,8 +1,6 @@ package net.dankito.utils.multiplatform -import platform.Foundation.NSFileManager -import platform.Foundation.NSURL -import platform.Foundation.lastPathComponent +import platform.Foundation.* actual class File actual constructor(path: String) : NSURL(fileURLWithPath = path) { @@ -19,7 +17,10 @@ actual class File actual constructor(path: String) : NSURL(fileURLWithPath = pat get() = lastPathComponent ?: "" actual val fileExtension: String - get() = filename.substringAfterLast('.', "") + get() = this.pathExtension ?: filename.substringAfterLast('.', "") + + actual val parent: File? + get() = this.URLByDeletingLastPathComponent?.absoluteString?.let { File(it) } actual fun mkdirs(): Boolean { diff --git a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/File.kt b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/File.kt index e6fd6b1f..dcf1191e 100644 --- a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/File.kt +++ b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/File.kt @@ -1,17 +1,15 @@ package net.dankito.utils.multiplatform -import java.io.File - -fun File.toFile(): net.dankito.utils.multiplatform.File { - return net.dankito.utils.multiplatform.File(this.absolutePath) +fun java.io.File.toFile(): File { + return File(this.absolutePath) } -actual class File actual constructor(path: String) : File(path) { +actual class File actual constructor(path: String) : java.io.File(path) { - actual constructor(folder: net.dankito.utils.multiplatform.File, filename: String) - : this(File(folder, filename).absolutePath) + actual constructor(folder: File, filename: String) + : this(java.io.File(folder, filename).absolutePath) internal constructor() : this("") // for object deserializers @@ -27,6 +25,9 @@ actual class File actual constructor(path: String) : File(path) { actual val fileExtension: String get() = this.extension + actual val parent: File? + get() = this.parentFile?.absolutePath?.let { File(it) } + actual override fun mkdirs(): Boolean { return super.mkdirs()