Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set date modified of files in Cocoa

How can I set the date modified attribute of a file in Cocoa? Thanks

like image 894
user635064 Avatar asked Apr 26 '11 13:04

user635064


1 Answers

What about NSFileManager setAttributes:ofItemAtPath:error: method?

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html

Attributes are a dictionary. You can set a modification date value with the NSFileModificationDate key.

Basically:

NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys: yourDate, NSFileModificationDate, NULL];

[[NSFileManager defaultManager] setAttributes: attr ofItemAtPath: yourPath error: NULL];
like image 159
Macmade Avatar answered Oct 28 '22 07:10

Macmade