Recent

Author Topic: Which program(s) opens such file?  (Read 889 times)

winni

  • Sr. Member
  • ****
  • Posts: 307
Re: Which program(s) opens such file?
« Reply #15 on: July 26, 2019, 10:24:31 pm »
Hi

The linux command line utility  to achieve that is named file

Read the man page about the three different ways to get the info, especially about the "magic" file info.

And if you can read C look into the sources of file

Winni

lucamar

  • Hero Member
  • *****
  • Posts: 2012
Re: Which program(s) opens such file?
« Reply #16 on: July 26, 2019, 11:24:35 pm »
Thanks, but using file would be just one step in the process: that of obtaining the mime-type of the file. And I can do that relatively easily by consulting the mime database directly.

I don't use file very much, truth be told; I find it useful only to guess the type of strange files or to ensure that a file is really what it appears to be: for example, whether a .doc is an MSWord file or plain text (which was very common in the old days before Word apropiated the extension), etc.

What I would really need is a command (or function) like:
Code: [Select]
whocanopen somefile.extBut it seems I'll have to write it myself ;)
« Last Edit: July 26, 2019, 11:27:39 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

toby

  • Jr. Member
  • **
  • Posts: 65
Re: Which program(s) opens such file?
« Reply #17 on: July 26, 2019, 11:32:48 pm »
technically anything can open anything - i'm sure you have done    vi aa.html      or   dillo a.mp4  or   dillo a,txt    you can even  do   mplayer 1,txt
the end result may not be what you want   (i don't recomment doing  vi a.mp4   or even vi google-saved-search-page-html  :)
(have you seen all the crap in what google sends you to track everything)


it is up to you to decide what the file can open  that is why i gave you the fmask/mask info


lucamar

  • Hero Member
  • *****
  • Posts: 2012
Re: Which program(s) opens such file?
« Reply #18 on: July 27, 2019, 12:23:27 am »
technically anything can open anything

Sure, and I do have my system set so that gedit tries to open some strange "not-really-but-almost text" files and so that ghex opens anything. :)

But users are used to see that some kind of files can be opened with "these programs", other kind with "those programs" and so on; and one has to take into account that "users" are prone to customizations: "no, I want this kind of files be opened with this  other program".

Quote
it is up to you to decide what the file can open  that is why i gave you the fmask/mask info

I think your'e misunderstanding what this thread is about. It's not about what my program can open but about which programs the sytem has configured to open "this file" whose name my program has. As I said above, IIRC, imagine that my program is a file manager: It doesn't open files by itself but needs to know which programs open each file.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

winni

  • Sr. Member
  • ****
  • Posts: 307
Re: Which program(s) opens such file?
« Reply #19 on: July 27, 2019, 12:33:14 am »
Hi!

Okay. As far as I know the linux system does not have such a service. That job is up to the different desktops. So you should look or ask what the gnome and KDE teams do to configure the relationship between filetype and application. Think that's the right direction.

Winni

toby

  • Jr. Member
  • **
  • Posts: 65
Re: Which program(s) opens such file?
« Reply #20 on: July 27, 2019, 12:47:23 am »
okay you win :)

when you do get to coding it - are you planning on using sqlite or?? just a text file? for the file types?


winni

  • Sr. Member
  • ****
  • Posts: 307
Re: Which program(s) opens such file?
« Reply #21 on: July 27, 2019, 01:02:35 am »
@lucamar

KDE stores for every desktop application one file with the suffix .desktop in /usr/share/applications. After a lot of multi-language stuff they contain all the mimetypes they can handle. But it seems that there are only installed applications, so you will never get a complete list. And so this is only the list for a specific desktop.

Winni

lucamar

  • Hero Member
  • *****
  • Posts: 2012
Re: Which program(s) opens such file?
« Reply #22 on: July 27, 2019, 02:01:01 am »
So you should look or ask what the gnome and KDE teams do to configure the relationship between filetype and application. Think that's the right direction.

Thanks. I already know (more or less) what they do: they store all that info following (more or less) the recomendations/specifications of freedesktop.org and the XDG. Leledumbo's post above explains it  quite well.

when you do get to coding it - are you planning on using sqlite or?? just a text file? for the file types?

I've started already (yesterday, in fact). I don't plan to store anything (it's not that kind of app); it's just a couple functions (which will multiply to a dozen "helpers", you'll see :) ); kind of:
Code: Pascal  [Select]
  1. function GetCmdsFor(const AFilename:String): TStringList;
  2. function GetDefaultCmdFor(const AFilename:String): String;

BTW, I accept suggestions for the functions' names :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

winni

  • Sr. Member
  • ****
  • Posts: 307
Re: Which program(s) opens such file?
« Reply #23 on: July 27, 2019, 02:09:23 am »
Captain Cook sails to Australia!

Good luck!

Winni