inessential by Brent Simmons

File creation date in Ruby on Macs

I couldn’t find a way to get the creation date of a file, using Ruby on a Mac. For the benefit of anyone searching for this same thing, here’s the solution I’m using. (Seems to work so far.)

Where f is the path to the file:

Time.parse(`mdls -name kMDItemContentCreationDate -raw #{f}`)

Uses the awesome mdls. (Do a man mdls in Terminal to learn more.)

(Note: File.atime, File.ctime, and File.mtime return the last access, change, and modification dates, respectively — but there’s no File method for the creation date. Also note that there may be a better way to do this that I just don’t know about.)

Update 3:39 p.m.: Ben Tucker posted a better version that’s not open to shell injection.