资源格式:
代码:
import os import shutil import uuid from data import name,department namelist= name.split("\n") departmentlist= department.split("\n") print(len(namelist)) path = os.getcwd() printpath = path+ "\\"+ "分类照片" os.mkdir(printpath) ##dirlist = os.listdir(path1) def search(path,mingz,bum): items = os.listdir(path) ## print(items) for name in items: path1 = path + "\\" + name if os.path.isdir(path1): ## print(path1) search(path1,mingz,bum) else: if mingz in name: printpathlist = os.listdir(printpath) #查看输入文件夹中的内容 printpath2 = printpath + "\\" + bum #创建出的部门文件夹 printfile = printpath2+ "\\" + name if bum in printpathlist: printpath2list = os.listdir(printpath2) #部门文件夹里的全部文件 for i in printpath2list: if mingz in i: mzmz = printpath2+"\\"+mingz+str(uuid.uuid1()) #重复之后的文件夹名称 newprintfile = mzmz + "\\" + name os.mkdir(mzmz) shutil.copyfile(path1,newprintfile) break else: shutil.copyfile(path1,printfile) else: os.mkdir(printpath2) shutil.copyfile(path1,printfile) num = 1 for idx in range(len(namelist)): print(num) name = namelist[idx] department = departmentlist[idx] search(path,name,department) num += 1 print("完事")