I am writing following program :
***import os
filepath=r'C:\TestData\openfolder.html'
abc=open(filepath,'w')
abc.writelines('<html><head></head><body>')
abc.writelines('<a href="os.startfile(filepath)">First Link</a>\n')
abc.writelines('</body></html>')***
What I want to do is if I click First Link on a browser, I should be able to open the folder having path as "Filepath". os.startfile works perfect for opening a folder but I don't know how to implement this inside some link. Thanks.
HTML can be used to open a folder from our local storage. In order to open a folder from our local storage, use 'HREF' attribute of HTML. In the HREF attribute, we specify the path of our folder.
To add a hyperlink to a file or folder:Click the Links toolbar button, or choose Insert > Hyperlink. Tip: Click the Task Panes toolbar button, click the Inspector tab, and then click the Hyperlink and Attachments tab. If a hyperlink already exists for the selection it will show here.
You need to use the file:/// protocol (yes, that's three slashes) if you want to link to local files. These will never open the file in your local applications automatically. That's for security reasons which I'll cover in the last section. If it opens, it will only ever open in the browser.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With