import os dict_suffix ={'doc':[],'docx':[], 'xls':[],'xlsx':[], 'ppt':[],'pptx':[]} def lsdir(path): for dirpath,dirnames,filenames in os.walk(path): for filename in filenames: suffix=filename[filename.rfind(r'.')+1:len(filename)].lower() if suffix in dict_suffix: dict_suffix[suffix].append(os.path.join(dirpath,filename)) return dict_suffix if __name__ == '__main__': # pl = r'D:workspace数据字典' old_pl=input('请输入路径:') if old_pl[-1] =='/': old_pl=old_pl[0:len(old_pl)-1] pl=old_pl.replace('/', '//') dic=lsdir(pl) for i in dic: if len(dic[i])>0 : print('文件类型:',i) [print(s) for s in dic[i]]