import os
def fileCopy(srcPath,desPath):
# 判断拷贝文件是否存在
if not os.path.exists(srcPath):
print("{}文件不存在".format(srcPath))
return
# 判断是否是文件
if not os.path.isfile(srcPath):
print("{}不是文件".format(srcPath))
return
# 打开源文件和目标文件
srcFile = open(srcPath,"rb")
desFile = open(desPath,"wb")
# 获取文件大小,一字节为单位
size = os.path.getsize(srcPath)
while size > 0:
# 读取1024字节
content = srcFile.read(1024)
# 写入
desFile.write(content)
size -= 1024
# 关闭文件
srcFile.close()
desFile.close()
# 执行拷贝
if __name__ == "__main__":
fileCopy("by.txt","a.txt")