find the last modified date of a csv file in swift

Here is a code snippet that demonstrates how to find the last modified date of a CSV file in Swift using FileManager and URL.

main.swift
let filePath = "path/to/your/csv/file.csv"
let fileURL = URL(fileURLWithPath: filePath)

do {
    let attributes = try FileManager.default.attributesOfItem(atPath: filePath)
    if let modificationDate = attributes[.modificationDate] as? Date {
        print("The last modified date of the CSV file is:", modificationDate)
    }
} catch let error {
    print("Error while getting file attributes:", error.localizedDescription)
}
429 chars
12 lines

In the above code, we first create a URL object for the CSV file path. We then use FileManager to get the attributes of the file at the given path. Finally, we extract the .modificationDate attribute from the attributes dictionary to get the last modified date of the CSV file.

gistlibby LogSnag