I have a folder which contains some directories and some html files. In these directories are some HTML files and also some folders and this continues on for a depth of 3/4 until you reach the end.

I am trying to recursively iterate over the HTML, extract 3 divs, save the files and move on to the next sub-folder until everything is done.

I thought my code was quite well-reasoned, but I am getting the error in the title whenever I try and run it. What have I done wrong? I have gotten the code running for just one folder but my recursion is not working.

```
import os
from bs4 import BeautifulSoup

def CleanUpFolder(dir):
    directory = os.listdir(dir)
    files = []

    for subdir, dirs, files in os.walk(dir):
        for file in files:
            if file.endswith('.html'):
                files.insert(0, file)

            for fileName in files:
                file = open(dir + "\\" + fileName)
                content = file.read()
                file.close()
                soup = BeautifulSoup(content)
                toWrite = soup.find("div", {"class": "title"})
                toWrite2 = soup.find("div", {"class": "main"})
                toWrite3 = soup.find("div", {"class": "price"})

                toCopy=""
                if toWrite:
                    toCopy += str(toWrite)
                if toWrite2:
                    toCopy += str(toWrite2)
                if toWrite3:
                    toCopy += str(toWrite3)

                file = open(dir + "\\" + fileName, 'w')
                file.write(toCopy)
                file.close()

            for folder in dirs: #Recursive call here
                if os.path.isdir(dir):
                    print dir
                    CleanUpFolder(dir)

dir = "C:\Users\FOLDER"
CleanUpFolder(dir)

```

What can I do here to help me parse this data effectively?

Let's assume my data structure is 6 directories, A,B,C,D,E and F. To navigate to F you must go to `C:\Users\FOLDER\A\B\C\D\E\F`, within each directory there are a number of .html files and potentially more than one folder also.

Many thanks for your time and guidance :).