I'm writing a script with PyQgis vthat descends into a directory tree and then visits files and creates a list of files with .tif and .ecw file extensions. The problem is that there are hundreds of directories in the root folder and os.walk takes too long and freezes Qgis.
The folder structure is something like this:
this is the code I have so far, but I need to exclude the junk directories (some of which have unique names) but the folders I need to access all have the same name, besides the parent directory ("unique name" in blue in the image above).
def list_files(inputdirectory):
r = []
for root, dirs, files in os.walk(inputdirectory):
for name in files:
if "ecw" in name or "tif" in name:
r.append(os.path.join(root, name))
return r