小编jon*_*jon的帖子

MacOS 和快速更改/设置文件创建日期

macOS 塞拉利昂、iMac、swift3

我正在尝试编写一个程序来更改文件的创建日期。我有很多扫描的照片和文档,我希望能够按字母或时间顺序存储。

我已经在 Objective-C 中实现了这一点,但在 swift 中却很挣扎。Apple API > Foundation > FileManager > setAttributes 实例方法应该可以解决我的问题。实例方法 ----- setAttributes( :ofItemAtPath:) 声明 --- f**c setAttributes( attribute: [FileAttributeKey : Any], ofItemAtPath path: String) throws

我无法编写这行代码以便它能够编译。

var isChangedBoolean = try fm.setAttributes(myAttributesDictionary: [FileAttributeKey : creationDate],ofItemAtPath : myPath)
Run Code Online (Sandbox Code Playgroud) ############## 我的代码
    let fm = FileManager()
    let myPath = "/Users/jon/a-1.jpg"  //original date  30/1/2013  = d/m/y

    //Convert date string to date object
    let myDateString = "24/11/2014"  // required date
    let dateFmt = DateFormatter()
    //dateFmt.timeZone = NSTimeZone.default
    dateFmt.dateFormat = "dd/MM/yyyy" …
Run Code Online (Sandbox Code Playgroud)

attributes creation swift3

2
推荐指数
1
解决办法
2481
查看次数

标签 统计

attributes ×1

creation ×1

swift3 ×1