how get list of files in a folder using javascript

懵懂的女人 提交于 2019-12-02 12:53:23

问题


I am working on project for desktop application. I am using Qt controls with visual c++. I am loading an html file in the QWebView as,

m_pWebView->load(QUrl("../../../demo/index_Splash_Screen.html"));

Now, what i want is, say, I have some .zip files in my location "c:\demo", I want list (or array of file names) of the files present in that directory.

How can i do this through javascript ?

PS: I went through this link, but it didnt match my requirement. I have not worked with of html, javascript and jquery. Please help me.


回答1:


I'm afraid you cannot access local files or directories using javascript due to security issues.

Edit: I hadn't thought about the file api so thought for a moment this might not be true, but without some user input to give permission, this still cannot be done.

This question has a good response from PhilNicholas:

I'm afraid I may be the bearer of bad news for your design: The action you are requesting expressly violates the security model as specified in the File API spec. The client implementation of FileReader() must make sure that "all files that are being read by FileReader objects have first been selected by the user." (W3C File API , 13. Security Considerations: http://www.w3.org/TR/FileAPI/#security-discussion).

It would be a huge security risk of browser scripts could just arbitrarily open and read any file from a path without any user interaction. No browser manufacturer would allow unfettered access to the entire file system like that.

Thinking about it however, if it is all being run locally, you could use ajax to query a server side script that could return the directory you request.




回答2:


If it is a Windows application then you could access the local filesystem by using ActiveX objects. You might have a look at this link Reading a txt file from Javascript

Note that activeX usage is possible only when using IE as browser/engine; I used to need it a while ago for developing an HTML application (.hta files).



来源:https://stackoverflow.com/questions/20265195/how-get-list-of-files-in-a-folder-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!