How Can I Get an Icon or thumbnail for a Specific file

后端 未结 4 1924
北恋
北恋 2021-01-25 06:01

I am searching for a way to get the icon associated with a certain file type on Linux.

Either using a shell script or python.

I prefer a native python method whi

4条回答
  •  感动是毒
    2021-01-25 06:49

    I found a solution, and I wrote a function to do the job

    #!/usr/bin/env python
    import gio, gtk, os
    
    def get_icon_filename(filename,size):
        #final_filename = "default_icon.png"
        final_filename = ""
        if os.path.isfile(filename):
            # Get the icon name
            file = gio.File(filename)
            file_info = file.query_info('standard::icon')
            file_icon = file_info.get_icon().get_names()[0]
            # Get the icon file path
            icon_theme = gtk.icon_theme_get_default()
            icon_filename = icon_theme.lookup_icon(file_icon, size, 0)
            if icon_filename != None:
                final_filename = icon_filename.get_filename()
        return final_filename
                
            
    print (get_icon_filename("/home/el7r/Music/test.mp3",64))
    

    thanks all

提交回复
热议问题