python 复制并重命名文件

来源:互联网 发布:手游端游数据互通 编辑:程序博客网 时间:2024/05/22 11:49
# -*- coding: cp936 -*-'''copy file and rename将某个目录下的文件修改文件名后复制到相同的文件夹'''import os,sys,shutilsource_folder=r'C:\Users\Dell\Desktop\YUVDataSet'file_list=os.listdir(source_folder)for file_obj in file_list:    file_path=os.path.join(source_folder,file_obj)        file_name,file_extend=os.path.splitext(file_obj)    new_name=file_name+'_30'+file_extend   #在文件名的最后加上’_30'    newfile_path=os.path.join(source_folder,new_name)        shutil.copyfile(file_path,newfile_path)<span style="white-space:pre"></span>#最后说一句,python的重命名是os.rename()

0 0
原创粉丝点击