如何循环文件夹中的文本文件,从每个文件中读取内容以使用javascript形成字符串数组

时间:2021-06-07 06:43:05
 var FSO = new ActiveXObject("Scripting.FileSystemObject");
 var f = FSO.GetFolder("/home/dir/*.txt");      

 try {
    // Get enumerator for files in directory
    var fe = new Enumerator(f.Files);
    // Check to see if file is a .java file
    for (;!fe.atEnd();fe.moveNext()){   
       alert("FIles" +"File Name: " + fe.item().path + "." + fe.item().name );
    } 
 }

As the above code does not work for Chrome.

由于上述代码不适用于Chrome。

1 个解决方案

#1


0  

I'm pretty sure activex doesn't work by default. you need an extension called Ietab and also need to have Internet Explorer installed. I haven't used this myself but presume it uses ie in a frame. I would question why you are trying to read the client file system from a browser. If it is business requirements I would imagine the browser is IE anyway so perhaps you should test in that browser.

我很确定activex默认不起作用。你需要一个名为Ietab的扩展,还需要安装Internet Explorer。我自己没有使用它,但假设它使用即在框架中。我会问你为什么要尝试从浏览器中读取客户端文件系统。如果是业务需求我会想象浏览器是IE,所以也许你应该在那个浏览器中测试。

#1


0  

I'm pretty sure activex doesn't work by default. you need an extension called Ietab and also need to have Internet Explorer installed. I haven't used this myself but presume it uses ie in a frame. I would question why you are trying to read the client file system from a browser. If it is business requirements I would imagine the browser is IE anyway so perhaps you should test in that browser.

我很确定activex默认不起作用。你需要一个名为Ietab的扩展,还需要安装Internet Explorer。我自己没有使用它,但假设它使用即在框架中。我会问你为什么要尝试从浏览器中读取客户端文件系统。如果是业务需求我会想象浏览器是IE,所以也许你应该在那个浏览器中测试。