I'm looking for an option to search specific subdirectories in python.
For instance a directory structure like this:
some_files/
common/
2009/
2010/
2011/
...
I only want to search for in the subdirectories that start with a 2, so that it must be something like 'some_files/2*'. I think it must be possible using glob.glob and os.walk(), but I can't get it to work.
Now i use:
files = [os.path.join(dirpath, f)
for dirpath, dirnames, files in os.walk(d)
for f in files if f.endswith(ext)]
but this doesn't fit the specific needs.
Can someone help me out, would be much appreciated!
You can use glob with dirpath to find matching directories:
Or if you really want a list comp: