PDA

View Full Version : To identify executable and other files in QT Application



augusbas
8th March 2010, 11:10
Hi,

I am using file dialog to open a particular folder or disk and see files in it which is of QT executable , text, image format files.

How do i identify whether the opened file is executable or text or image file. As all you know , No file extension for linux files.

( My idea is if file opened is executable i will use Qprocess to execute it otherwise if it is text file i will use Qtextstream to read it .)









I

pitonyak
8th March 2010, 16:17
You mention Linux. Do you know the file command? It will tell you a file type. Take a look here to see how it works

http://linux.about.com/library/cmd/blcmdl1_file.htm

Note, that this will identify links as links. On Windows, I believe that file extension is used.

squidge
8th March 2010, 18:00
Linux uses mime types instead of extensions, so you would get the mime type for your file and if it says "executable", then you would use QProcess to execute it/etc.

If you are unsure of the mime type used for a particular file, you can use the 'mimetype' command to figure it out. It's like 'file' but uses mime types instead of descriptions.

pitonyak
8th March 2010, 18:29
I use fedora, and it supports the file command, but not mimetype. I do have a high level of curiosity, however, so I poked around a bit.

I am stating what I believe to be true with hopes that you will correct me if I am incorrect.


Gnome uses mime types to associate applications with files.
Gnome mime types use magic numbers to recognize the mime type.
There may be multiple associations for a specific type; for example, an OOo document may associate to an OOo document type and also to a ZIP file. This is, of course, as it should be.


I looked at the gnome mime-type stuff in the file /etc/gnome-vfs-mime-magic

Very interesting...