Reputation: 31
How can one find out the type of a file in objective c,i.e, finding out whether the file is a a pdf,xls,doc or an image or a directory?
Upvotes: 0
Views: 428
Reputation: 38412
If you can't trust the extension to be accurate, you'll need to look at the "magic numbers", the first few bytes of the file.
Directories are a different animal. You can test that with stat() or its Objective-C equivalent.
Upvotes: 0
Reputation: 11330
I'm not sure if this is against SO policy, but I wrote a high-level wrapper around libmagic
, MagicKit.framework
. It has an iOS target that you can statically link against your iOS application, if that's what you want. The feature set is somewhat spartan, but it does return Uniform Type Identifiers (as well as MIME types and human-readable descriptions) if you want to broadly categorise your files into multimedia, documents, etc.
Upvotes: 2