简体   繁体   English

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

[英]How to loop through text files in a folder, read the contents from the each file to form a string array using javascript

 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。

I'm pretty sure activex doesn't work by default. 我敢肯定,ActiveX在默认情况下不起作用。 you need an extension called Ietab and also need to have Internet Explorer installed. 您需要一个名为Ietab的扩展,还需要安装Internet Explorer。 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. 如果是业务需求,我想该浏览器还是IE,那么也许您应该在该浏览器中进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM