现在我用这个代码:如何解决fileAttributesAtPath警告问题?
NSDictionary* attr = [[NSFileManager defaultManager] fileAttributesAtPath:file traverseLink:YES];
,并得到警告:
'fileAttributesAtPath:traverseLink:' is deprecated
谁知道改用什么?
谢谢!
现在我用这个代码:如何解决fileAttributesAtPath警告问题?
NSDictionary* attr = [[NSFileManager defaultManager] fileAttributesAtPath:file traverseLink:YES];
,并得到警告:
'fileAttributesAtPath:traverseLink:' is deprecated
谁知道改用什么?
谢谢!
改为使用attributesOfItemAtPath:error:
。
'attributesOfItemAtPath:error:'不支持符号链接。所以你的建议与问题中的'traverseLink:YES'不一样。 –
你应该阅读documentation:
fileAttributesAtPath:traverseLink:
Returns a dictionary that describes the POSIX attributes of the file specified at a given. (Deprecated in Mac OS X v10.5. Use attributesOfItemAtPath:error: instead.)
'attributesOfItemAtPath:error:'不支持符号链接。所以你的建议与问题中的'traverseLink:YES'不一样。 –
使用attributesOfItemAtPath:error:
NSError* error;
NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:file error:&error];
'attributesOfItemAtPath:error:'不支持符号链接。所以你的代码与问题中的'traverseLink:YES'不一样。 –
接受的答案忘了将问题处理traverseLink:YES
。
改进的答案是同时使用attributesOfItemAtPath:error:
和stringByResolvingSymlinksInPath
:
NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:[file stringByResolvingSymlinksInPath] error:nil];
'attributesOfItemAtPath:错误:'不支持符号链接。所以你的建议与问题中的'traverseLink:YES'不一样。 –