• python文件文件夹检索照片文件


    资源格式:

     代码:

    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("完事")
  • 相关阅读:
    设备驱动开发之缓冲区读写操作
    什么是80Plus
    INF Manufacturer Section
    C++编程获得某台机器的IP地址
    INF DestinationDirs Section
    importlib模块
    django的内置信号
    auth模块(登录验证)
    头像文件的预览
    powerDesiger 常用设置
  • 原文地址:https://www.cnblogs.com/jayxuan/p/15598698.html
Copyright © 2020-2023  润新知