I am working on getting a human readable description of certain file type, and I only know the file extension. E.G. I would like to get "C Header Source File" from type "h", also "Zip Archieve" from "zip"
I googled, and find a solution with LSCopyKindStringForTypeInfo:
- (NSString *)humanReadableFiletype:(NSString *)ext
{
NSString *res;
LSCopyKindStringForTypeInfo(nil, nil, (CFStringRef)ext, (CFStringRef *)&res);
return [res autorelease];
}
It works on most file types except the ones taken by Preview.app, so "jpg", "gif" and "pdf" would be interpreted as "Preview Document". (XCode 3.2.5, Snow Leopard)
Will you guys help me?
Thanks!
Try using UTIs (Uniform Type Identifiers) and associated API, as documented here:
#import <Carbon/Carbon.h>
- (NSString *)humanReadableFileTypeForFileExtension:(NSString *)extension
{
CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)extension, NULL);
NSString *utiDescription = (NSString *)UTTypeCopyDescription(fileUTI);
CFRelease(fileUTI);
return [utiDescription autorelease];
}