Wednesday, August 13, 2014

Get the Folder Tree and Read HTML Files in Python

Hi All,

This might be really stupid, but it was kind of useful for me. I downloaded some templates for a website and I wanted to open them all in Chrome at once. Going to the folders again and again is not that interesting,right? So here's a simple python script that will help to read all the index.html files from the main folder you have saved your templates.

import os
import webbrowser

print "Index File Reader"
print "*"*20

folderPath = "C:\Website Templates"
fileTreeTuple = os.walk(folderPath)

for root, dirs, files in fileTreeTuple:
    for fileName in files:
        if fileName == "index.html" or fileName == "index.htm":
            fullPath = os.path.join(root,fileName)
            print fullPath
            webbrowser.open_new_tab(fullPath)

Thank You :-)

Reference :
https://docs.python.org/2/library/os.html#os.listdir
https://docs.python.org/2/library/webbrowser.html?highlight=webbrowser#webbrowser

1 comment:

  1. This is a great article on different software development blogs available. Whilst there is a lot of content, there are some awesome developers that are also worth. I'd also recommending keeping an eye on these Yiioverflow software developers for Nodejs, Angualr, Ionic, ReactJS and Yiiframework.

    ReplyDelete