[Pythonmac-SIG] Discovering file type

Bob Ippolito bob at redivi.com
Thu Feb 10 17:08:59 CET 2005


On Feb 10, 2005, at 6:19, Enrico Franchi wrote:

> I need to write a function that gets a filepath and gives back what 
> kind of file is that in a consistent way.
>
> I thought i could use my beloved old TYPE and CREATOR, then I realized 
> that in MacOS X not every file has got them.
> So i can check both the extension and the HFSFileType.
>
> Still i need a consistent way to express the file type. I need 
> something that given an HFSFileType returns the 'most used' extension, 
> or something that from an extension determines a file type.
> Is there anything like that?

Since 10.3, LaunchServices's UTType functions should be able to do 
this, but I don't think they're wrapped in Python (wouldn't be hard to 
loadBundleFunctions them into PyObjC, though).  I've also never tried 
them, so I don't know how complete the database is.

-bob



More information about the Pythonmac-SIG mailing list