Hi All,
I'm porting a Mac application that gets/sets file creation and modification dates via FileManager. I get an inscrutable thrown error in setAttributes
(when the attributes dictionary is non-empty), and an empty response to attributesOfItem
. Is it expected that these are unimplemented, or am I missing something. I'm using the latest 5.3 on swift.org on Ubuntu 20.4.
//
// FileFixer.swift
// FixEncodedDate
//
// Created by William Dillon on 1/9/21.
//
import Foundation
public func fixFileDate(url: URL, date: Date) throws {
try FileManager().setAttributes(
[FileAttributeKey.creationDate: date,
FileAttributeKey.modificationDate: date],
ofItemAtPath: url.path
)
}
public func getFileDate(url: URL) throws -> Date? {
let attributes = try FileManager().attributesOfItem(atPath: url.path)
return attributes[FileAttributeKey.creationDate] as? Date
}