zoukankan      html  css  js  c++  java
  • 乱序批量精确修改文件名



    # --** coding="UTF-8" **--
    
    
    import os
    
    # 导入包含字典的文件 
    # import dirt
    
    
    def accurate_rename(file_path, name_dirt):
        """
        :param file_path: input your file path
        :param name_dirt: import file name dictionary
        :return:none;
        """
    
        fileList = os.listdir(file_path)
    
        count = 0
    
        try:
            for i in fileList:
                old_name = file_path + i
    
                new_name = file_path + name_dirt[i]
    
                os.rename(old_name, new_name)
    
                print(i + "已改为" + name_dirt[i])
    
                count += 1
    
        except Exception as result:
            print(result)
    
    
        print("[%d]个文件完成重命名" % count)
    
    
    if __name__ == '__main__':
        accurate_rename("../dirtpath/", name_dirt)
    
    
    
     
  • 相关阅读:
    学习记录18
    学习记录17
    学习记录16
    小白的心酸连网历程
    学习记录15
    学习记录14
    学习记录13
    学习记录12
    学习记录10
    语法糖
  • 原文地址:https://www.cnblogs.com/jrri/p/11386214.html
Copyright © 2011-2022 走看看