| FAQ Index - Search - Recent Changes - Everything - Add entry |
23.46. How do I get file mimetype and other info
Previously this was possible using the "get_mime_type" method of gnomevfs. Since gnomevfs has been replaced by gio, here we are going to show how to use gio in order to receive the mimetype of a file:
>>> import gio
>>> f = gio.File('/home/user/Documents/test.odt' )
>>> f_info = f.query_info('standard::content-type')
>>> mime_type = f_info.get_content_type()
>>> mime_type
'application/vnd.oasis.opendocument.text'
In the same way one can retrieve other file information by replacing the query string "standard::content-type" with some other attribute from [www.pygtk.org] s
In this general case one should use the corresponding "get_attribute_X" method instead of "get_content_type".
