How to open a windows folder when clicking on some link on a HTML page using Python

前端 未结 4 701
孤独总比滥情好
孤独总比滥情好 2021-01-06 05:38

I am writing following program :

***import os
filepath=r\'C:\\TestData\\openfolder.html\'
abc=open(filepath,\'w\')
abc.writelines(\'&         


        
相关标签:
4条回答
  • 2021-01-06 06:08

    Alain's answer works.

    <'a href="FOLDER_PATH" target="_explorer.exe">Link Text<'/a>

    I removed the tick marks at the beginning and end, and found that it works in

    • Internet Explorer - opens a Windows Explorer window

    • Firefox (Windows and Linux), but opens a new tab - same as target="_blank"

    • Chrome - opens a new tab like Firefox

    I also noticed that / and \ (forward and backward slashes) are equal in html links - they can even be mixed.

    0 讨论(0)
  • 2021-01-06 06:26

    You can't. Clicking a link to a file in a browser will not launch the application associated with that file type on the OS. You can apparently do some funky stuff with JavaScript to launch particular filetypes with particular applications (see here: http://forums.devshed.com/asp-programming-51/launching-ms-word-to-open-file-from-a-hyperlink-55714.html) but apart from that the web browser is not the file browser.

    0 讨论(0)
  • 2021-01-06 06:27

    Try to use URI with file: scheme like file:///C:/TestData/openfolder.html in your html:

    <a href="file:///C:/TestData/openfolder.html">Link to test data</a>
    

    Here is article on using file URIs in Windows.

    UPD (extraction from comments): Each browser has its own way to handle such urls. At least Internet Explorer 8 under Windows 7 opens links in Windows Explorer as was required by jags.

    Finally, for dynamic pages the web server is required. If one is needed take a look at discussion on creating simple web services using python.

    0 讨论(0)
  • 2021-01-06 06:30
    <a href="FOLDER_PATH" target="_explorer.exe">Link Text</a>
    

    Replace FOLDER_PATH with the path of the folder you want to open in explorer.

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