简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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