So when creating a directory or attempting to change its attributes for the NSFileModificationDate I seem to only be able to affect the creation date when viewed through Finder.

When using createDirectoryAtPath_withIntermediateDirectories_attributes_error_( ) and passing in the NSFileModificationDate attribute it seems to change the Created: date when viewed with Finder.

When using setAttributes_ofItemAtPath_error_( ) and passing the same attribute as above I get the same results.

Is NSFileModificationDate too low-level to affect with ASOC?

How did you try to do it? This code worked fine for me:

on applicationWillFinishLaunching_(aNotification)
        set fm to current application's NSFileManager's defaultManager()
        set today to current application's NSDate's |date|()
        set thePath to POSIX path of (path to desktop as string) & "Root"
        set dict to current application's NSDictionary's dictionaryWithObject_forKey_(today,current application's NSFileModificationDate)
		fm's setAttributes_ofItemAtPath_error_(dict,thePath,missing value) 
	end applicationWillFinishLaunching_

It also worked to leave out the dictionary creation line, and set the attribute inline:

fm's setAttributes_ofItemAtPath_error_({NSFileModificationDate:today},thePath,missing value)


I noticed one difference in your code vs mine and that is that I passed the key for NSFieModificationDate as a string in quotes instead of current application’s NSFileModificationDate. But after changing my code to match your format I got the same results as I did before. The Created date is changed but not the Modified.

log current application's NSFileManager's defaultManager()'s setAttributes_ofItemAtPath_error_(current application's NSDictionary's dictionaryWithObject_forKey_(current application's NSDate's dateWithString_("2010-01-21 14:00:00 -0400"), current application's NSFileModificationDate), theDestinationPath, missing value)

Granted, my code is all strung together, not sure if that makes any difference. Any help is appreciated. Thanks. --Andrew

My real goal to get the attributesOfItemAtPath and use them to pass to the createDirectoryAtPath. Doing that got me absolutely nothing. Below is the dictionary results from attributesOfItemAtPath. Are some attributes listed below off limits?

    NSFileCreationDate = "2011-08-15 12:54:43 -0400";
    NSFileExtensionHidden = 0;
    NSFileGroupOwnerAccountID = 80;
    NSFileGroupOwnerAccountName = admin;
    NSFileModificationDate = "2011-08-15 12:54:44 -0400";
    NSFileOwnerAccountID = 1796773915;
    NSFileOwnerAccountName = athomson;
    NSFilePosixPermissions = 493;
    NSFileReferenceCount = 4;
    NSFileSize = 136;
    NSFileSystemFileNumber = 710047;
    NSFileSystemNumber = 234881026;
    NSFileType = NSFileTypeDirectory;

When I use your date, I get both the creation date and the modification date set to 1/21/2010. I think this just has something to do with setting a date in the past. If I run the app again with 1/24/2010 as the date, the creation date is still 1/21/2010 but the modification date is changed to 1/24/2010. When I tested my code, I used a folder I created last week and changed the modification date to today which worked as expected.


This is exactly what I would expect but do not see the same results. No idea why though. --Andrew

So what exactly are you seeing if you run it twice with different dates? And, if you log attributesOfItemAtPath, do you get something different there than in the finder?

A more basic question is why would you want to set either the creation or modification dates manually, since those are created for you with the correct dates? I’m actually a little surprised that the API lets you set the creation date to something other than when it was actually created.


I’m home now and running the same code on a different machine and it works fine. Not sure if my machine at work is problematic or if maybe it’s the difference between 10.6 and 10.7? This is the second time you’ve helped me where something doesn’t work while using my work machine but does at home. Go figure. Thanks for your help. --Andrew