• 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)
  • 相关阅读:
    后缀数组简要总结
    2019CCPC网络赛
    2019 Multi-University Training Contest 6
    洛谷P4145——上帝造题的七分钟2 / 花神游历各国
    扫描线——POJ1151
    2012Noip提高组Day2 T3 疫情控制
    2012Noip提高组Day1 T3 开车旅行
    JZOJ.5335【NOIP2017模拟8.24】早苗
    三套函数实现应用层做文件监控
    LLVM一个简单的Pass
  • 原文地址:https://www.cnblogs.com/adong7639/p/9266988.html
Copyright © 2020-2023  润新知