最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - how get list of files in a folder using javascript - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Nov 28, 2013 at 11:38 Chintan SoniChintan Soni 25.3k26 gold badges112 silver badges176 bronze badges 2
  • Dont think u can.. but a solution is to create a service ( for example REST) that returns the filelist in the folder you want, and than call the service with jquery.. – Coy Commented Nov 28, 2013 at 11:53
  • Did any one have experience working with Qt controls ? Will Qt control QWebView work as expected, using this: codeproject./Articles/2019/Find-files-with-JavaScript – Chintan Soni Commented Nov 28, 2013 at 12:44
Add a ment  | 

2 Answers 2

Reset to default 2

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/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.

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).

发布评论

评论列表(0)

  1. 暂无评论