Python 3.6.1 (default, Mar 22 2017, 06:17:05)
[GCC 6.3.0 20170321] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> def isimage(fn):
... return os.path.splitext(fn)[-1] in ('.jpg', '.JPG', '.png', '.PNG')
...
>>> isimage('abs.jpg')
True
>>> isimage('abc.txt')
False
>>> dirpath = '/home/zyy/汽车/卡槽'
>>> for r, ds, fs in os.walk(dirpath):
... for fn in fs:
... if not isimage(fn):
... continue
... fname = os.path.join(r, fn)
... print(fname)
...