__author__ = 'zhangcx' import os import shutil path = r'C:UserszhangcxDesktop' 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)