def walkfolder(toppath, pred):
for entry in scandir.scandir(toppath):<EOL><INDENT>if not entry.is_dir() or not pred(entry.name):<EOL><INDENT>continue<EOL><DEDENT>yield entry.path<EOL>for p in walkfolder(entry.path, pred):<EOL><INDENT>yield p<EOL><DEDENT><DEDENT>
walk folder if pred(foldername) is True
:type toppath: str
:type pred: function(str) => bool