最近做了一个文件自动归类的脚本,测试效果不错,源码: path = 'D://Users/Administrator/Desktop/Walden' path2 = path + '/' files = os.listdir(path) for f in files: folder_name = path + f.split('.')[-1] folder_name2 = path2 + f.split('.')[-1] if not os.path.exists(folder_name2): os.makedirs(folder_name2) shutil.move(path2+f,folder_name2) else: shutil.move(path2 + f,folder_name2)