objective c - Get file type description by extension -


How can I get file type details such as Finder.app only use file extensions? In other words, I want to get that area in NSString:

Here's a little nasty 'n' that's what you want:

  NSOpenPanel * OpenPanel = [[Enswapel Alok] Init]; [OpenPenel runmodel]; NSString * path = [[OpenPanel URL] path]; NSString * type = [[NSWorkspace shared workspace] typeoff file: path error: NULL]; NSLog (@ "% @", [[NSWorkspace shared workspace] LocalType forType: type]);  

The Open panel lets you select the file NSWorkspace first to determine the file's UTI (its path has been given), and then UTI Used to obtain a string describing the local type of file.

Edit:

If you want to use only file extensions in a positive way, then use these three lines instead of the three of the above:

  NSString * extension = [[OpenPanel URL] path] pathExtension]; CFStringRef uti = UTTypeCreatePreferredIdentifierForTag (kUTTagClassFilenameExtension, (__Briff CFStringRef) extension, NULL); NSLog (@ "% @", [[NSWorkspace sharedWorkspace] Localized name text FORType: (__ bridge NSString *) UTI);  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -