2012-01-26 72 views

回答

8

改为使用attributesOfItemAtPath:error:

+0

'attributesOfItemAtPath:错误:'不支持符号链接。所以你的建议与问题中的'traverseLink:YES'不一样。 –

0

特别注意事项

因为这个方法没有返回错误信息,它已被弃用的Mac OS X v10.5中的。 使用setAttributes:ofItemAtPath:error:改为。

link

+0

'attributesOfItemAtPath:error:'不支持符号链接。所以你的建议与问题中的'traverseLink:YES'不一样。 –

0

你应该阅读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.)

+0

'attributesOfItemAtPath:error:'不支持符号链接。所以你的建议与问题中的'traverseLink:YES'不一样。 –

4

使用attributesOfItemAtPath:error:

NSError* error; 
NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:file error:&error]; 
+0

'attributesOfItemAtPath:error:'不支持符号链接。所以你的代码与问题中的'traverseLink:YES'不一样。 –

1

接受的答案忘了将问题处理traverseLink:YES

改进的答案是同时使用attributesOfItemAtPath:error:stringByResolvingSymlinksInPath

NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:[file stringByResolvingSymlinksInPath] error:nil];