【发布时间】:2014-01-06 20:42:56
【问题描述】:
我正在学习 Objective-C,我正在将 Applescript 实用程序转换为 Objective-C。
我需要了解如何获取目录中所有文件的NSFileCreationDate,以便将最新文件复制到另一个位置。我不知道如何获取目录中每个文件的NSFileCreationDate。
此代码获取目录列表,但每次我尝试获取 NSFileCreationDate 时,它都会给我封闭文件夹的 NSFileCreationDate。
我必须读取一个 plist 文件才能获得备份位置的路径。
- 为备份位置读取 plist 文件
- 获取文件的创建日期
-
将最新的文件复制到 * wholepath , 桌面上的文件
NSString filePath = [@"~/Library/Preferences/com.viive.Viive.plist" stringByExpandingTildeInPath]; NSMutableDictionary plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSString *value; value = [plistDict objectForKey:@"backupPath"]; NSFileManager *filemgr; NSArray *filelist; filemgr = [NSFileManager defaultManager]; filelist = [filemgr contentsOfDirectoryAtPath:value error: nil]; NSArray *array = filelist; NSUInteger index = 0; for (id element in array) { NSLog(@"Element at index %lu is: %@", (unsigned long)index, element); index++; } NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath://// error:nil]; NSDate *result = [fileAttribs fileCreationDate]; //or fileModificationDate NSLog(@"%@",result); ////// NSString* desktop = [@"~/Desktop/LOGS-I-NEED-" stringByExpandingTildeInPath]; NSString* computername = [[NSHost currentHost] localizedName]; NSString* wholepath = [desktop stringByAppendingString:computername];
我已经用谷歌搜索了这个信息,因为我是新手,所以我找到的答案对我来说没有多大意义。如果有人知道更好的方法,我会全力以赴。
谢谢大家!!
【问题讨论】:
标签: objective-c macos xcode5