1

In PySide, when I use QDirIterator, how I can filter on files by name?

In the documentation, it talks about the parameter nameFilters:

But when I try it, it doesn't filter the files by extension:

from PySide import QtCore

it = QtCore.QDirIterator('.', nameFilters=['*.py'])
while it.hasNext():
    print it.next()

>> ./.
>> ./..
>> my_script.py
>> another_file.txt

With this code, I expected to get only the files with the extension .py.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
JuanPablo
  • 23,792
  • 39
  • 118
  • 164

1 Answers1

1

The nameFilters parameter is not a keyword argument.

Unfortunately, PySide never raises an error if you pass keyword arguments that don't exist, which is a very poor design. APIs should never fail silently when given invalid inputs.

Anyway, your code will work correctly if you use a positional argument:

it = QtCore.QDirIterator('.', ['*.py'])
ekhumoro
  • 115,249
  • 20
  • 229
  • 336