打开本地文件

/**
 * 通过js打开本地文件目录
 * @param filename
 */
function openLocalFile(fileName) {
  try {
    var obj = new ActiveXObject("WScript.shell");
    if (obj) {
      obj.run("'" + fileName + "'");
      obj = null;
    }
  } catch(e) {
    alert('路径文件不存在/请在IE浏览器访问打开/组件未注册');
  }
}

// 调用函数
openLocalFile('file:///C:/demo.txt');

方式二

  <input type="file" id="fileInput" webkitdirectory directory />
          <button onclick="document.getElementById('fileInput').click()">
            选择文件夹
          </button>

 

posted @ 2023-10-13 15:27  ThisCall  阅读(43)  评论(0编辑  收藏  举报