有没有办法知道NSHFSTypeOfFile失败的原因?

时间:2014-05-08 07:19:10

标签: objective-c macos cocoa foundation

我有以下代码来检查mac中文件的文件类型:

OSType GetFileTypeFromPath( const std::string & inFilePath )
{
    NSString * pathToFile = [[NSString alloc] initWithBytes:inFilePath.data()
                                                     length:inFilePath.size() * sizeof(char)
                                                   encoding:NSUTF8StringEncoding];

    NSString *fileType =  NSHFSTypeOfFile( pathToFile );
    return NSHFSTypeCodeFromFileType( fileType );;
}

我在https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSFileTypeForHFSTypeCode

中找到了函数'NSHFSTypeOfFile'

函数返回一些文件的结果。我对pdf文件感兴趣。对于某些pdf文件,它可以正常工作,但对于其他文件,函数返回的字符串为nil。我不知道文件或我提供的文件路径是否有任何问题(比如编码。有没有办法让函数NSHFSTypeOfFile失败?

0 个答案:

没有答案
相关问题