Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
713 views
in Technique[技术] by (71.8m points)

html - JavaScript: Read files in folder

EDIT: I'm trying to read all the files in a specific folder and list the files in there, not read the content of a specific file. I just tried to simply create an FileSystemObject and it doesn't do anything either. I show an alert (which pops up) beforfe making the FileSystemObject, and one after it (which isn't shown). So the problem is in simply creating the object.

Original:

I am trying to read all the files in a folder by using JavaScript.

It is a local HTML file, and it will not be on a server, so I can't use PHP I guess.

Now I'm trying to read all the files in a specific given folder, but it doesn't do anything on the point I make a FileSystemObject

Here is the code I use, The alert shows until 2, then it stops.

    alert('1');
    var myObject, afolder, date;
    alert('2');
    myObject = new ActiveXObject("Scripting.FileSystemObject");
    alert('3');
    afolder = myObject.GetFolder("c:\tmp");
    alert('4');
    date = afolder.DateLastAccessed;
    alert("The folder"+name+" is a temporary folder.");

Am I doing this the right way?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The method I found with a Google search uses HTML5 so if you are using a modern browser you should be good. Also the tutorial page seems to check if the browser you are using supports the features. If so you should be good to follow the tutorial which seems pretty thorough.

http://www.html5rocks.com/en/tutorials/file/dndfiles/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...