Showing posts with label FileRead. Show all posts
Showing posts with label FileRead. Show all posts

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