Get attributes of file

 Problem

I want to get the attributes of a files, at given location: creation date, file type, owner, etc.



 Recipe


// Create a FileManager instance

let fileManager = NSFileManager.defaultManager()

// Get attributes of 'myfile.txt' file

do {
    let attributes = try fileManager.attributesOfItemAtPath("myfile.txt")
    print(attributes)
}
catch let error as NSError {
    print("Ooops! Something went wrong: \(error)")
}
				

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)

 

 Playground