trying to walk through a directory and subdirectories I am getting error in the following code. Here, I am trying to call the constructor recursively.
import os
from os.path import isfile, join
class CovPopulate:
fileList = list()
def __init__(self,path):
self.path = path
for f in os.listdir(self.path):
if isfile(join(self.path,f)):
if f.endswith(".txt"):
fileList.append(join(self.path,f))
else:
CovPopulate(f)
Traceback : -
CovPopulate(r"C:\temp")
File "<pyshell#1>", line 1, in <module>
CovPopulate(r"C:\temp")
File "C:/fuzzingresults/CovPopulate.py", line 11, in __init__
fileList.append(join(self.path,f))
NameError: global name 'fileList' is not defined
but, I have alread defined the fileList = list()
This time I 've checked for the synch errors :/