桌面文件自动整理脚本
__author__ = 'zhangcx' import os import shutil path = r'C:\Users\zhangcx\Desktop' lst = sorted(os.listdir(path)) for i in lst: a,b = os.path.splitext(i) b = b[1:] print('{f}:{ext}'.format(f=a,ext=b)) if b: olddir = '%s\%s'% (path, i) newdir = '%s\%s' % (path,b.lower()) if not os.listdir(path).__contains__(b.lower()): os.mkdir(newdir) shutil.move(olddir,newdir) #print(olddir) #print(newdir)