user2242044
user2242044

Reputation: 9213

glob.iglob to find all .txt files in all sub-directories yields error

Simple code gives the below error. It's directly from the docs (https://docs.python.org/3/library/glob.html)

TypeError: iglob() got an unexpected keyword argument 'recursive'

import glob
for filename in glob.iglob('C:\\**\\*txt', recursive=True):
    print filename

Upvotes: 5

Views: 7049

Answers (2)

botchniaque
botchniaque

Reputation: 5084

The recursive parameter has been added in python 3.5, which means version 3.4.3 also has that problem.

If you don't want to upgrade your python version, you can use glob2, which supports recursive calls (**) by default.

Upvotes: 7

carlosdc
carlosdc

Reputation: 12142

It seems you're using Python 2.7 and reading the Python 3.5 documentation.

Upvotes: 9

Related Questions