Ah yes.
You're calling os.path.isfile(f)
where f
is the filename within the path
. You'll need to provide an absolute path. If, indeed, this call is necessary (it should always return True
).
Try changing your for-loop to:
qualified_filenames = (os.path.join(path, filename) for filename in fnames)
for f in qualified_filenames:
And you should be set!
Also, the calls to os.chdir()
are not needed.
And, as I suggested in the comments, filterfiles
should look more like this:
def filterfiles(f):
ext = os.path.splitext(f)[1][1:]
return ext in fileFilter
(You missed a return
).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…