在Python中获取文件关联 [英] Get file association in Python
问题描述
有一个名为 xdg-mime ,就像xdg-open一样,但打印信息而不是试图打开文件。 / p>
xdg-mime查询文件类型/tmp/foobar.png
打印文件/tmp/foobar.png的MIME类型,在本例中为image / png
xdg-mime查询默认图片/ png
打印.desktop文件名在Windows上,如果找不到API,也许可以使用 assoc code>或
ftype
,它们是 cmd
的一部分。
I want to get the program associated with an extension, in both Linux and Windows. I know that I can execute xdg-open in Linux or start in Windows, but I'm gonna open a media file on a remote server, so using this method would open the web browser, not the default media player. How can I get the default application for an extension?
There is a program called xdg-mime that's like xdg-open, but prints the information rather than trying to open the file.
xdg-mime query filetype /tmp/foobar.png
Prints the MIME type of the file /tmp/foobar.png, in this case image/png
xdg-mime query default image/png
Prints the .desktop filename of the application which is registered to open PNG files.
On Windows, if you can't find an API, maybe you can use assoc
or ftype
, which are part of cmd
.
这篇关于在Python中获取文件关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!