标签:pos == coding 文件夹 env int port std pat
__author__ = ‘ZHHT‘ #!/usr/bin/env python # -*- coding:utf-8 -*- import os # #1. 获取要重命名的文件夹 名字 folder_name = input("请输入批量重命名文件的文件夹名称:") # #2. 获取制定的文件夹中的所有 文件名字 Base_Path = os.path.dirname(os.path.abspath("练习4")) old_file_name_temp = os.listdir() for fname in old_file_name_temp: if fname == folder_name: Base_Path = Base_Path + "\\" + folder_name print(Base_Path) old_file_name_path = os.listdir(Base_Path) print(old_file_name_path) #3. 重命名 for name in old_file_name_path: old_file_name = Base_Path + "\\" + name print(old_file_name) position = name.rfind(".") new_file_name = Base_Path + "\\" + name[:position] + "文件复件" + name[position:] os.rename(old_file_name,new_file_name)
标签:pos == coding 文件夹 env int port std pat
原文地址:https://www.cnblogs.com/zhaohongtaodepython/p/9372834.html