for dirpath, dirnames, filenames in os.walk(someDir):
    for f in filenames:
        ext = os.path.splitext(f)[1]
try:
    function = funcMap[ext]
except KeyError:
    pass
else:
    abspath = os.path.join(dirpath, f)
with open(abspath) as f:
    function(f.read())
обход файлов в python