swift - 在 Swift 中设置文件属性

标签 swift macos

如何在 Swift for OSX 中设置文件的文件属性(例如 NSCreationDate)?

我可以在 Objective-C 中做到这一点,但不知道如何在 Swift 中做到这一点。

最佳答案

对于 swift 3 使用:

//let path = "/path/to/file"

let attributes = [
    FileAttributeKey.creationDate: NSDate(),
    // FileAttributeKey.modificationDate: NSDate() for modification date...
]

do {
    try FileManager.default.setAttributes(attributes, ofItemAtPath: path)
} catch {
    print(error)
}

关于swift - 在 Swift 中设置文件属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33846694/

相关文章:

ios - 如何将数据从 UIPageViewController 传递到它的 "subviews"之一?

ios - 解析实时查询 "Invalid HTTP upgrade",代码 : 403)

ios - 在另一个函数中调用函数内部函数

macos - 连接耳机后能否将声音发送到扬声器?

python - Pycharm conda env 不显示通过 pip 安装的包

swift - AVAudioSession setCategory 在 Swift 4.2 中的可用性

swift - 缩放和置换节点的最佳方法是什么?

c++ - wxWidgets 3.1.0 和 Mac OS X El Capitan (10.11)

macos - Rust cargo dylib 说明

regex - 如何在 unix (osx) 中搜索/替换一堆文本文件