__author__ = 'zhangcx'import osimport shutilpath = 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)