-
-
Save pgtwitter/c8d799d013d860a26aaa459e098c5fa4 to your computer and use it in GitHub Desktop.
objective-c/cocoa reflectTimestampSourcePath:destPath:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| + (BOOL)reflectTimestampSourcePath:(NSString *)sourcePath destPath:(NSString *)destPath | |
| { | |
| NSFileManager *fm = [NSFileManager defaultManager]; | |
| NSError *error = nil; | |
| // 1. ソースファイルのタイムスタンプを取得 | |
| NSDictionary *sourceAttrs = [fm attributesOfItemAtPath:sourcePath error:&error]; | |
| if (!sourceAttrs) { | |
| NSLog(@"Failed to get source attributes: %@", error); | |
| return NO; | |
| } | |
| NSDate *creationDate = sourceAttrs[NSFileCreationDate]; | |
| NSDate *modificationDate = sourceAttrs[NSFileModificationDate]; | |
| // 2. 宛先ファイルにタイムスタンプを反映 | |
| NSDictionary *attrsToSet = @{ | |
| NSFileCreationDate: creationDate, | |
| NSFileModificationDate: modificationDate | |
| }; | |
| BOOL success = [fm setAttributes:attrsToSet ofItemAtPath:destPath error:&error]; | |
| if (!success) { | |
| NSLog(@"Failed to set attributes: %@", error); | |
| return NO; | |
| } | |
| return YES; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment