why not ben

ben tucker's virtual life. elsewhere: work, doings, incoming.

December 18, 2008 at 6:30pm
home

File creation date in Ruby on Macs

Brent Simmons posted about how to get the file creation data in Ruby on a Mac. His solution is good, but suffers from shell injection. Here’s a slightly modifed version that’s not susceptible (that I know of):

require 'open3'
require 'time'

def creation_time(file)
   Time.parse(Open3.popen3("mdls", 
                        "-name",
                        "kMDItemContentCreationDate", 
                        "-raw", file)[1].read)
end

Notes

  1. bentucker posted this