I have another question. I based the function in my first post on the code for another similar function I wrote, which returns a list of all files with an appropriate extension. However, in this function I don't return the list of files until the very end. Why does this work here when it doesn't in the function I posted previously? Or have I done something wrong here as well?
def findfileswithext(path, exts=NC_EXTENSIONS, recurl=3, i=0, files=[]):
"""Return a list of filepaths to files with an extension in exts
Recurl is the level of recursion, or depth of subdirectories to search"""
if not os.path.isdir(path): return
for item in os.listdir(path):
itempath = os.path.join(path, item)
if os.path.isdir(itempath) and i < recurl:
findfileswithext(itempath, exts, recurl, i+1)
elif os.path.splitext(item)[1] in exts:
files.append(itempath)
return files