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

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