(May-10-2020, 06:24 AM)Kumarkv Wrote: TypeError: scandir: illegal type for path parameterYou get this error because you use Python 3.5.
Have to use Python 3.6 or newer for
os.walk()
to take pathlib
object.You use can it directly like this
os.walk(dir_to_scan)
.You should of course install a new version Python 3.8 (3.6-3.7) and pip installation under Windows
Then you can also drop the old string formatting
%s' % dirName
and use f-string.from pathlib import Path import os dir_to_scan = r"C:\code\img" p = Path(dir_to_scan) for root, dirs, files in os.walk(p): for fname in files: if fname.endswith(('.jpg', '.png')): print(f'Image found --> {fname}')
Output:Image found --> nrk.png
Image found --> test.jpg