import os import docx def scanfile(rootdir): result = [] for f in os.walk(rootdir): for files in f[2]: if files.endswith('.py'): result.append(os.path.join(rootdir,os.path.join(f[0],files))) return result doc = docx.Document() for i in scanfile('/home/deepcam/src/plazaface_serv'): print i