Question

I'm trying to set the filesystem creation time for a file on Mac OS using a ruby script.

On Mac OS X the 'ctime' represents the last time of inode modification rather than the file creation time, thus using ruby's File.utime() to set ctime will not help.

Using this hint [ http://inessential.com/2008/12/18/file_creation_date_in_ruby_on_macs ] I can retrieve a file's creation time:

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

...but any idea on how to set it using ruby?

-- UPDATE --

Okay, I think I can actually do this with File.utime in ruby.

Even though the ctime is technically not used by Mac OS to track file creation time, when you use utime to update the ctime (along with the mtime, which must be simultaneously set) the filesystem appears to magically also update the creation time as per kMDItemContentCreationDate.

So to set filename to a ctime of 1st Oct 2010 and a mtime of 2nd Oct 2010:

File.utime(Time.strptime('011010', '%d%m%y'), Time.strptime('021010', '%d%m%y'), filename)

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top