# -*- coding: cp936 -*-
'''
copy file and rename
将某个目录下的文件修改文件名后复制到相同的文件夹
'''
import os,sys,shutil
source_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()
python 复制并重命名文件
最新推荐文章于 2024-08-14 02:04:50 发布