def JudgeFile(self, pathname): for name, type in self.filetype.items(): if pathname in type: return name return "无法判断类型文件"
class DeskTopOrg(object): def __init__(self): self.filetype = FileType()
def Organization(self):
filepath = input("请输入需要整理的文件夹路径: ")
paths = glob.glob(filepath + "/*.*") print('paths-->',paths) for path in paths: try: if not os.path.isdir(path):
file = os.path.splitext(path)
filename,type = file print('type-->',type) print("filename-->",filename) print('path-->',path)
dir_path = os.path.dirname(path) print('dir_path-->',dir_path)
savePath = dir_path + '/{}'.format(self.filetype.JudgeFile(type)) print('savePath-->',savePath) if not os.path.exists(savePath):
os.mkdir(savePath)
shutil.move(path, savePath) else:
shutil.move(path, savePath) except FileNotFoundError: pass print("程序执行结束!")
if __name__ == '__main__': try: while True:
desktopOrg = DeskTopOrg()
desktopOrg.Organization() print("---->你的文件已经整理完成。")
a = input('---->请按回车键退出:') if a == '': break except BaseException: print("ERROE:路径错误或有重复的文档")