智慧大石
import osimport shutildir="C:\\Users\\Lenovo\\Desktop\\figure-it\\学习\\python";fileNames = os.listdir(dir);if(len(fileNames)>0): for fn in fileNames: if(fn.find("_") != -1): n = fn[0:len(fn)-4]; names = n.split('_'); last = names[-1]; suffix = fn[len(fn)-4:len(fn)]; path = ""; for name in names: path = os.path.join(path,name); fullpath = os.path.join(dir,path); if not os.path.exists(fullpath): os.makedirs(fullpath); shutil.copy(os.path.join(dir,fn),fullpath); os.remove(os.path.join(dir,fn)); os.rename(os.path.join(fullpath,fn),os.path.join(fullpath,last+suffix));