Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 374
jags Avatar asked Aug 04 '12 07:08

jags


People also ask

What are the ways to make an HTML link open a folder?

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.

Can I hyperlink to a 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.

How do I link to a local file in HTML?

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.


1 Answers

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.

like image 104
Vladimir Avatar answered Sep 28 '22 00:09

Vladimir