我正在学习,Objective-C
并且正在将Applescript实用程序转换为Objective-C
。
我需要了解如何获取NSFileCreationDate
目录中所有文件的位置,以便将最新文件复制到另一个位置。我不知道如何获取NSFileCreationDate
目录中的每个文件。
这段代码获取目录的列表,但是每次我尝试获取NSFileCreationDate
它时,都会得到NSFileCreationDate
封闭文件夹的。
我必须阅读plist文件才能获取备份位置的路径。
将最新文件复制到* Wholepath,在桌面文件
NSString filePath = [@“〜/ Library / Preferences / com.viive.Viive.plist” stringByExpandingTildeInPath]; NSMutableDictionary plistDict = [[ NSMutableDictionary分配] 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];
我已经在Google上搜索了此信息,由于我是新手,所以我发现的答案对我来说没有多大意义。如果有人知道更好的方法,我将不知所措。
谢谢大家!
这应该有助于:
for (NSString file in array) {
NSLog (@"%@", file);
NSString *path = [filePath stringByAppendingPathComponent: file];
NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
NSDate *result = [fileAttribs fileCreationDate]; //or fileModificationDate
NSLog(@"%@",result);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句