find the creation date of a directory in swift

You can use the FileManager class provided by Apple to get the file attributes for the directory, which includes the creation date. Here's an example:

main.swift
// set your directory path
let directoryPath = "/path/to/your/directory"

do {
    let attributes = try FileManager.default.attributesOfItem(atPath: directoryPath)
    if let creationDate = attributes[FileAttributeKey.creationDate] as? Date {
        print("The creation date of the directory is: \(creationDate)")
    }
} catch {
    print("Error: \(error)")
}
362 chars
12 lines

The attributesOfItem(atPath:) method returns a dictionary of file attributes for the file or directory at the specified path. The creation date is stored in the FileAttributeKey.creationDate key of the dictionary, so we can retrieve it from there as a Date object. If an error occurs while retrieving the attributes, the catch block will print the error message.

gistlibby LogSnag