写copy函数

import os
def copy(path1, path2):
filename = os.path.basename(path1)
if os.path.isdir(path2) and os.path.isfile(path1):
path2 = os.path.join(path2, filename)
if os.path.exists(path2):
print("已有同名文件!")
with open(path1, "rb") as f1, \
open(path2, "wb") as f2:
content = f1.read()
f2.write(content)
copy(r'G:\salar\day17\random模块.py', r'G:\salar\day15')
posted @ 2020-02-03 12:00  冰灬荷  阅读(176)  评论(0编辑  收藏  举报