[英]How do you get the Finder “Kind” for a file?
我想得到一個文件的Finder“Kind”。 例如,對於文件“foo.css”,我想要字符串“CSS樣式表”。
到目前為止,我正在做這樣的事情:
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: filename];
NSString *utiType;
NSError *error;
BOOL success = [fileURL getResourceValue: &utiType
forKey: NSURLTypeIdentifierKey
error: &error];
if (!success) {
NSLog(@"failure during reading utiType: error = %@", error);
return;
}
NSString *utiDescription = (__bridge NSString *) UTTypeCopyDescription((__bridge CFStringRef) utiType);
if (utiDescription) {
// use utiDescription here...
}
這給了我UTI的人類可讀名稱,在某些情況下效果很好(“foo.html”給出“HTML文本”),但對於CSS文件,它返回nil,所以顯然與Finder不同。顯示在“種類”欄中。
你怎么得到那種文件?
嘗試LSCopyKindStringForURL
,傳遞文件URL。
我能夠獲得一個帶有typeOfFile的.css文件類型的字符串:error:后跟localizedDescriptionForType : ,但字符串不是你想要的“CSS樣式表”,它是“Dashcode CSS Document”。 其他擴展的其他一些示例:
ext typeOfFile localizedDescriptionForType
------------------------------------------------------------------
.css com.apple.dashcode.css Dashcode CSS Document
.php public.php-script PHP script
.html public.html HTML text
.txt public.plain-text text
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.