oldFileName = input("请输入要拷贝的文件名字:") #提示输入文件
oldFile = open('student.txt','rb') #以读的方式打开文件
fileFlagNum = oldFileName.rfind('.') #提取文件的后缀
if fileFlagNum > 0:
fileFlag = oldFileName[fileFlagNum:]
#组织新的文件名字
newFileName = oldFileName[:fileFlagNum] + '[复件]' + fileFlag
newFile = open('student[1].txt','wb') #创建新文件
#把旧文件中的数据一行一行的复制到新文件中
for lineContent in oldFile.readlines():
newFile.write(lineContent)
oldFile.close()
newFile.close()
python-制作文件的备份
最新推荐文章于 2024-05-21 22:44:12 发布