Extracting file icon and display in html

拥有回忆 提交于 2019-12-07 16:50:00

问题


Evening Everyone,

I have started doing some research for an application i want to write using the electron framework. I have figured out how to display what i want to the user with the exception of the icons. There is a part of the application where the user can type a path and it will list the files in that path, i would like to pull the icon from the files so its displayed just like it would be in the windows file explorer. This is where i have been running into a roadblock and I'm looking for some guidance.

Is there a method in nodejs that would allow me to provide a file path and in return get a image back i can pass to HTML? Im new to nodejs so i figured i would ask and see if anyone knew of an easy way.


回答1:


There is icon-extractor you can use it like this to extract any app icon from the system , but it must be an**".exe"** file.

var iconExtractor = require('icon-extractor'); var fs= require('fs');

iconExtractor.emitter.on('icon', function(data){
console.log('Here is my context: ' + data.Context);
console.log('Here is the path it was for: ' + data.Path);
var icon = data.Base64ImageData;

fs.writeFile('img.png', icon, 'base64', (err) => {
 console.log(err);

});
});

iconExtractor.getIcon('ANY_TEXT','PAHT_TO_APP.exe');


来源:https://stackoverflow.com/questions/44090459/extracting-file-icon-and-display-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!