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)
  • 相关阅读:
    centos安装composer
    fmt.Printf()
    php进程,线程,异步
    php异步处理
    php安装swoole扩展
    冒泡排序
    快速排序
    php的foreach指针
    无密钥登陆
    ubuntu18.04切换阿里云源
  • 原文地址:https://www.cnblogs.com/adong7639/p/9266988.html
Copyright © 2011-2022 走看看