For python >= 3.5 you can use **
, recursive=True
:
import glob
for x in glob.glob('/path/**/*.c', recursive=True):
print(x)
If recursive is
True
, the pattern**
will match any files and zero or moredirectories
andsubdirectories
. If the pattern is followed by anos.sep
, only directories andsubdirectories
match.
Note:
Python3.6
seems to default to recursive=True
when using **
so it can be omitted.