Sorry, this is not a Pythonista question, it's a Python Question. I have looked this up, but I don't get it.
The below is just walking through the dir structure. Just copied the code from stackflow. Well I added the yield as I wanted to return a generator.
What I am having difficulty with is filtering. I want to introduce ignore dir lust as well as define what file types (ext) I want returned.the filter conditions are not a problem. I am just not sure what to do if I want to ignore a file either based on its ext or dir.
My simple idea was to use continue if it failed my filter test otherwise yield.
From what I can ascertain, this does not work, the generator terminates. Eg, no more values. I am not even sure it's possible to have conditional tests inside a generator to skip items. I know I could return some flag, but that's ugly.
The code without filtering
def allfiles(self):
for path, subdirs, files in os.walk(self.root_dir):
for filename in files:
f = os.path.join(path, filename)
yield f