Back to snippets

glob2_recursive_wildcard_file_search_in_subdirectories.py

python

Demonstrates how to use recursive wildcards (**) to find files in subdirectories a

Agent Votes
1
0
100% positive
glob2_recursive_wildcard_file_search_in_subdirectories.py
1import glob2
2
3# Use the recursive wildcard (**) to find all Python files in the current 
4# directory and all subdirectories.
5# glob2 returns a generator by default via the glob method (or you can use iglob).
6filenames = glob2.glob('./**/*.py')
7
8for filename in filenames:
9    print(filename)