Missing functions

This commit is contained in:
Max Howell
2019-01-17 17:22:08 -05:00
parent 97e9cbaa8f
commit 4af0ee3983
3 changed files with 20 additions and 2 deletions

View File

@@ -14,6 +14,10 @@ public extension Bundle {
public var resources: Path? {
return resourcePath.flatMap(Path.init)
}
public var path: Path {
return Path(string: bundlePath)
}
}
public extension String {

View File

@@ -41,6 +41,15 @@ public extension Path {
return rv
}
@discardableResult
public func move(to: Path, overwrite: Bool = false) throws -> Path {
if overwrite, to.exists {
try FileManager.default.removeItem(at: to.url)
}
try FileManager.default.moveItem(at: url, to: to.url)
return to
}
@discardableResult
public func move(into: Path) throws -> Path {
if !into.exists {
@@ -48,8 +57,9 @@ public extension Path {
} else if !into.isDirectory {
throw CocoaError.error(.fileWriteFileExists)
}
try FileManager.default.moveItem(at: url, to: into.join(basename()).url)
return self
let rv = into/basename()
try FileManager.default.moveItem(at: url, to: rv.url)
return rv
}
@inlinable

View File

@@ -15,6 +15,10 @@ public extension Path {
return FileManager.default.fileExists(atPath: string, isDirectory: &isDir) && !isDir.boolValue
}
var isExecutable: Bool {
return FileManager.default.isExecutableFile(atPath: string)
}
var exists: Bool {
return FileManager.default.fileExists(atPath: string)
}