import osdef 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')
来源:https://www.cnblogs.com/hadibingjing/p/12255066.html