python_文件的赋值

import os

def Copy_file(pathSrc,pathDest):
    with open(pathSrc,'r',encoding='utf-8')as PS,open(pathDest,'w',encoding='utf-8') as PD:
        for line in PS:
            PD.write(line)
    print("复制成功")

def fileName(pathSrc,pathDest):
    if os.path.exists(pathDest):
        copy_pathDest = pathDest.rsplit('.',1)
        copy_pathDest=copy_pathDest[0]+"副本."+copy_pathDest[1]
        Copy_file(pathSrc,copy_pathDest)
    else:
        Copy_file(pathSrc, pathDest)


pathSrc = input('输入源文件:')
pathDest = input('输入目标文件:')
fileName(pathSrc,pathDest)

猜你喜欢

转载自blog.csdn.net/Py_CCY/article/details/76652302