现在我使用这段代码:
NSDictionary* attr = [[NSFileManager defaultManager] fileAttributesAtPath:file traverseLink:YES];
并收到警告:
'fileAttributesAtPath:traverseLink:' is deprecated
谁知道要使用什么呢?
谢谢!
答案 0 :(得分:8)
改为使用attributesOfItemAtPath:error:
。
答案 1 :(得分:4)
使用attributesOfItemAtPath:error:
NSError* error;
NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:file error:&error];
答案 2 :(得分:1)
接受的答案忘记了处理问题的traverseLink:YES
。
改进的答案是同时使用attributesOfItemAtPath:error:
和stringByResolvingSymlinksInPath
:
NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:[file stringByResolvingSymlinksInPath] error:nil];
答案 3 :(得分:0)
答案 4 :(得分:0)
你应该阅读documentation:
fileAttributesAtPath:traverseLink:
返回描述文件POSIX属性的字典 指定的。 (在Mac OS X v10.5中不推荐使用 attributesOfItemAtPath:error:代替。)