zoukankan      html  css  js  c++  java
  • python 批量修改文件名

    import os
    # with open("shijie_small_youtu_align_failed.txt","r") as face_file:
    #     for line in face_file.readlines():
    #         srcpath = line.strip().split("/")
    #         dstpath = ""
    #         num = 0
    #         for path in srcpath:
    #             if num == 5:
    #                 path = "shijie_small_youtu_MTCNN_Alignment_Margin32"
    #             num += 1
    #             dstpath += path
    #             dstpath += "/"
    #         dstpath = dstpath[0:-1]
    #         print(line[0:-1])
    #         print(dstpath)
    #         cmd = "cp " + dstpath + " " + line[0:-1]
    #         os.system(cmd)
    
    def findAllfile(path, allfile):
        filelist =  os.listdir(path)  
        for filename in filelist:  
            filepath = os.path.join(path, filename)  
            if os.path.isdir(filepath):
                #print(filepath)  
                findAllfile(filepath, allfile)  
            else:  
                allfile.append(filepath)  
        return allfile  
    
    
    #mv /DATA/share/publicdata/stars/zhouxun/u=3942420804,889887287&fm=27&gp=0.jpg /DATA/share/publicdata/stars/zhouxun/7_zhouxun_8.jpg
    
    
    
    clusterpath = "/DATA/share/publicdata/stars"
    filelist =  os.listdir(clusterpath) 
    floder_ID_index = 0
    for filename in filelist:  
        filepath = os.path.join(clusterpath, filename)  
        
        if os.path.isdir(filepath):
            print(filepath)
            floder_ID_index += 1
            print(floder_ID_index)
            filepath_split = filepath.strip().split("/")
            floder_ID = filepath_split[-1]
            image_files = findAllfile(filepath,[])
            #print(image_files)
            face_index = 1
            for image in image_files:
                dstname = clusterpath + "/" + floder_ID + "/" + str(floder_ID_index) + "_" + floder_ID + "_" + str(face_index) + ".jpg"
                image = "'" + image + "'"
                print(image)
                print(dstname)
                face_index += 1
                cmd = "mv " + image + " " + dstname
                os.system(cmd)
  • 相关阅读:
    对象与引用
    聊天室小程序
    tcp程序设计--客户端获取服务器输入输出流
    线程小例子--进度条
    线程小例子--控制输出
    ngnix反向代理
    使用vuex管理数据
    vue列表到详情页的实现
    vue-实现一个购物车结算页面
    localstorage本地存储的应用
  • 原文地址:https://www.cnblogs.com/adong7639/p/9266988.html
Copyright © 2011-2022 走看看