使用 Swift 以友好的方式处理文件和目录。
一些示例
import PathKit
let caches = Path.systemDirectory(for: .caches)
let home = Path.home
let parent = home.parent
let root = Path.root
let current = Path.current
let test = current.child("test")
print(test.isDirectory)
print(test.children().filter(\.isFile))
do {
let work = try home.add("my-work-dir")
print(work.location)
try test.delete()
try test.create()
let a = current.child("a")
try a.create()
let b = current.child("b")
let c = current.child("c")
let d = current.child("d")
try a.copy(to: b)
try a.link(to: c)
try a.move(to: d, force: true)
}
catch {
print(error.localizedDescription)
}
像往常一样使用 Swift Package Manager 即可
.package(url: "https://github.com/binarybirds/path-kit", from: "1.0.0"),
别忘了将 “PathKit” 添加到你的 target 作为依赖项!
.product(name: "PathKit", package: "path-kit"),
就这样。
WTFPL - 想干啥就干啥许可证。