1

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.

Chintan Soni
  • 24,761
  • 25
  • 106
  • 174
  • 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 Nov 28 '13 at 11:53
  • Did any one have experience working with Qt controls ? Will Qt control `QWebView` work as expected, using this: http://www.codeproject.com/Articles/2019/Find-files-with-JavaScript – Chintan Soni Nov 28 '13 at 12:44

2 Answers2

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

Community
  • 1
  • 1
Alfie
  • 2,341
  • 2
  • 28
  • 45
  • Do you know if Qt control `QWebView` work as expected, using this: http://www.codeproject.com/Articles/2019/Find-files-with-JavaScript ? – Chintan Soni Nov 28 '13 at 13:04
  • I couldn't really comment on that unfortunately, but as Qt is cross-platform oriented, my guess would be the underlying rendering engine is probably Webkit. In which case I doubt it will work as according to that link, "your browser should have access to run ActiveX objects", and I think that's beyond Webkit's capabilities. – Alfie Nov 28 '13 at 15:13
  • Thank you, sir. But i wonder, that IT industry is growing so fast, still we are facing the problems that doesn't have solutions...:( – Chintan Soni Nov 29 '13 at 03:12
  • In some ways I hope this is a problem that doesn't get solved. The thought of javascript on any website being able to access my files without permission is a scary one. Maybe you could have a look at WebSocket in HTML5, potentially you could have your desktop application serve file directory requests to the WebSocket? An ugly solution I know, but they all are for this problem. – Alfie Nov 29 '13 at 10:46
1

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

Community
  • 1
  • 1
SoulSeek
  • 31
  • 3