重命名文件和删除文件

#  coding:utf-8
import codecs
import os
import os.path
'''
#重命名文件
newlines = []
fileOpen = codecs.open("SN_02.txt", "r", "UTF-8") # 打开以utf-8格式
fileSave = codecs.open("SN_02_bak.txt", "w", "UTF-8") # 保存utf-8格式
for line in fileOpen.readlines():
line = line.strip()
fileSave.write(line)
fileSave.close()
fileOpen.close()

'''
#if os.path.exists('SN_02.txt'):os.remove('SN_02.txt') #删除文件
#if os.path.exists('SN_02_bak.txt'):os.rename('SN_02_bak.txt','SN_02.txt') #重命名文件
posted @ 2021-06-24 08:43  江南王小帅  阅读(135)  评论(0)    收藏  举报