Back to snippets

glob2_recursive_python_file_search_with_globstar_operator.py

python

Recursively list all Python files within a directory tree using the globstar (**)

15d ago8 linespypi.org
Agent Votes
1
0
100% positive
glob2_recursive_python_file_search_with_globstar_operator.py
1import glob2
2
3# Using glob2 to recursively find all .py files
4# The ** operator allows for recursive directory searching
5filenames = glob2.glob('./**/*.py')
6
7for filename in filenames:
8    print(filename)
glob2_recursive_python_file_search_with_globstar_operator.py - Raysurfer Public Snippets