setting creation and modification date problem

You are probably right. Any ideas how you will fix it or account for it?

Weird… I changed my time zone in the Date & Time preference pane to Denver. I assume that’s what you are using. I still get the improper time with that setting… so I’m confused.

I think what is really weird is that no matter what your date/time settings are it should not effect a time you are specifically setting on a file. What you set should be what you get back. Something else seems to be going on here. I am searching the net to see if anyone has posted similar situation.

Out of curosity, what is the mod date if you open the file, make a change and close it?

Is it still an hour earlier?

No, the mod date is right… 3:09 PM here on the east coast.

Try this script and see what the results are.

Yes, that script works. The problem is it doesn’t do anything to the creation date. I want that ability. I use this when I’m backing up files with Chronosync. If the creation or mod dates are different a backed-up file is overwritten, so I use this when I don’t want a particular file to be overwritten when backing up.

True, but at least this narrows down the issue to the SetFile command and not something with your system or time settings.

Have you considered writing a foundation tool?

Well if nobody has any ideas, then I’ll have to try something more drastic… but I still have hope somebody has an idea how to work around this.

If you us -mt it changes both created and modified dates. You could then issue another command to change the modified to a different date.

So, as an example:

Unfortunately this doesn’t work right. It only impacts the creation date of a file if the mod date you are setting is before the current creation date. For example, using the text.txt file we created with a creation date of 10/03/2008. If you touch it with a date of 11/03/2008 as you suggest then the creation date stays as 10/03/2008. So touch doesn’t really change creation dates. Thanks for the suggestion though.

I am guessing you have already done this but if not… :slight_smile:

There could be better error checking and you could have the tool process all the files instead of passing them in one at at time but it appears to be working.

Excellent Craig. I didn’t realize there were NSFileCreationDate and NSFileModificationDate cocoa attributes for NSFileManager… so no I haven’t tried that. But i definitely will! Thanks. I’ll report back how it works when I get the chance to try your code… probably tomorrow.


It’s the same thing for me here.

My solution is to use the “SetFile” (May 2007 or older) instead of the “SetFile” (September 2007 or newer).

You can find it in the “Xcode Tools” on Tiger.

Or in the ( MacOSXUpdate, MacOSXUpdCombo ) package :
SetFile is in the the resources folder in a package like this (/Library/Receipts/MacOSXUpd10.4.10.pkg)

Hi Craig,

memory management alert! If you retain objects, you are responsible to release them.
This is not so important in a CLI, which will be terminated at once, but you should always consider memory management.
In this case you can omit all retain messages, they are not necessary

So true. I have been building FileMaker Pro databases and websites for the last few months and this is the first Objective-C code I have written in a while. How fast we forget the basics! :wink:

Most of the time I would rather retain and then release though, as Hank can testify, autorelease can bite you in the butt. If you retain it, you don’t have to worry whether it is going to be there when you want to use it.

In the same scope you don’t have to worry. The system will keep args alive during the whole method

I have an old 10.4 install with SetFile from Sept 12, 2006. Using that gives me the same results so this didn’t solve the problem for me. I’m going to try Craig’s obj-c code now and will report back.

Thank you Craig! :smiley:

Using your suggested code I finally have a working solution! I posted the tool, the code, and a suggested applescript for using it on my website. You can see it here:

You are very welcome. Glad I could help!

I like all the error checking. That makes this very useful and distributable.

Good job on the website post. I am sure there are a lot of people who will find this useful. There really is very little on the internet on how to do this.