How do I limit os.walk
to only return files in the directory I provide it?
def _dir_list(self, dir_name, whitelist):
outputList = []
for root, dirs, files in os.walk(dir_name):
for f in files:
if os.path.splitext(f)[1] in whitelist:
outputList.append(os.path.join(root, f))
else:
self._email_to_("ignore")
return outputList
I think the solution is actually very simple.
use
to only do first iteration of the for loop, there must be a more elegant way.
The first time you call os.walk, it returns tulips for the current directory, then on next loop the contents of the next directory.
Take original script and just add a break.
Don't use os.walk.
Example:
This is how I solved it
You could also do the following: