问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
不是帮题主写过了?有什么其他问题吗?
import os
source=input('请输入源文件名:')
target=input('请输入目标文件名:')
if os.path.exists(source):
tpath=os.path.dirname(target)##得到目标文件夹路径
if not os.path.exists(tpath):#不存在路径则创建
os.makedirs(tpath)
r=open(source,'rb')
w=open(target,'wb')
while True:
strb=r.read(1024)
if strb==b'':
break
w.write(strb)
r.close()
w.close()
else:
print('%s不存在'%source)

source = input('源文件名:')
target = input('目标文件名:')
with open(source, mode='rb') as f:
data = f.read()
with open(target, mode='wb') as f:
f.write(data)
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>>
https://vip.csdn.net/askvip?utm_source=1146287632