how get list of files in a folder using javascript

前端 未结 2 959
暖寄归人
暖寄归人 2021-01-24 07:51

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(\         


        
相关标签:
2条回答
  • 2021-01-24 08:31

    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 讨论(0)
  • 2021-01-24 08:35

    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.

    0 讨论(0)
提交回复
热议问题