Added parent property

This commit is contained in:
dankito 2020-07-12 12:41:07 +02:00
parent 82628d8a6b
commit 563efc0ad8
3 changed files with 15 additions and 11 deletions

View File

@ -13,6 +13,8 @@ expect class File(path: String) {
val fileExtension: String
val parent: File?
fun mkdirs(): Boolean

View File

@ -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 {

View File

@ -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()