I am trying to set the creation and change dates in a file.
NSFileManager *fileManager = [NSFileManager defaultManager]; NSDate *now = [NSDate date]; NSDictionary *timestampAttr = [NSDictionary dictionaryWithObjectsAndKeys: now, NSFileCreationDate, now, NSFileModificationDate, nil]; BOOL ret = [fileManager setAttributes:timestampAttr ofItemAtPath:path error:&err];
Date modified successfully changed for file. Creation date has not changed. What for?
ret true, and err is zero. -attributesOfItemAtPath returns a dictionary containing both keys in timestampAttr , and the correct (modified) modification date and the incorrect (unmodified) creation date.
Edit: Use OS X version 10.6. The base SDK of the Xcode project is 10.5. The file is located on my computer only on the hard drive (without RAID), in a folder inside my home folder. The file is inside the application package, if that matters.
Edit: This simple example works:
#import <Cocoa/Cocoa.h> int main(void) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSFileManager *m = [NSFileManager defaultManager]; NSString *path = ...; [m setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSDate date],NSFileCreationDate,nil] ofItemAtPath:path error:nil]; [pool drain]; return 0; }
I pasted the code above into the application that I originally asked about, setting the attributes for the same file as the simple example (on my desktop). When the code is inside the application, it does not work.
Edit: Alright, this is crazy. The simple example above worked (my colleague and I both saw how it worked on my computer), but now it does not work.