Read filetype info from file



  • Hi, everybody,

    I use QFileInfo to read some information directly from the file, like date/time of creation, last saved etc... This works really simple, but I wonder, how it is possible to get also information about the type of file. If you rightclick a file in the explorer and open the properties window, you can see infos about the filetype, like "Libre Writer Document" or "Gimp Picture" ... Is this info stored in the file itself, and when yes, is there a way to read out this info?

    Thanks in advance,
    cheops


  • Qt Champions 2016

    @cheops said:

    Is this info stored in the file itself,

    No. It's saved system wide. And it's desktop environment specific. So Gnome will save the associations in one place, KDE in another, Windows has its own handling.

    is there a way to read out this info?

    Probably, but it'd be tied to the system and you have to code it manually for each supported OS.

    Kind regards.



  • @cheops Hi!

    Strictly speaking there is nothing such as a filetype. A file is a file. But depending on the content you'll want the file to be viewed / modified / whatever with this or that application. That's what file extensions on MS DOS were invented for; to help the OS to choose the right application to open a particular file. On other systems, such as Linux, file extensions can be used but aren't mandatory. On such systems there are additional mechanisms in place to determine the right application. E.g. some file formats use a magic number in the first bytes.

    tl;dr: file(1)



  • @Wieland Thanks for the explanation!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.