1、利用new ActiveXObject("Scripting.FileSystemObject"),可以实现读取指定文件夹内的所有文件,然后通过atEnd和moveNext API一个一个获取到图片:
function readMMSmessageFolder(){ var filePath = "H:\\MMSmessage\\"; var fso = new ActiveXObject("Scripting.FileSystemObject"); //加载控件 var f = fso.GetFolder(filePath); var underFiles = new Enumerator(f.files); //文件夹下文件 var _html = ''; var i = 0; for (; !underFiles.atEnd(); underFiles.moveNext()){ i++; var fn = "" + underFiles.item(); _html += '<div class="item"><a href="javascript:;" onclick="openMMSmessageInImg('+i+')"><img src="'+fn+'" /></a></div>'; } document.querySelector('#messageListBody').innerHTML = _html; }2、利用new ActiveXObject("WScript.Shell"),可以实现调用windows图片查看器,打开对应的图片:
function openMMSmessageInImg(index){ var filePath = "H:\\MMSmessage\\"; var fso = new ActiveXObject("Scripting.FileSystemObject"); //加载控件 var axo = new ActiveXObject("WScript.Shell"); var f = fso.GetFolder(filePath); var underFiles = new Enumerator(f.files); //文件夹下文件 var _html = ''; var i = 0; for (; !underFiles.atEnd(); underFiles.moveNext()){ i++; if(i === index){ var fn = "" + underFiles.item(); axo.run("rundll32.exe C:\\WINDOWS\\system32\\shimgvw.dll,ImageView_Fullscreen "+fn); } } }