文件拷贝,,#coding:cp93
文章由Byrx.net分享于2019-03-23 05:03:12
文件拷贝,,#coding:cp93
#coding:cp936'''Created on 2011-6-21@author: tangly文件拷贝'''import osdef MyCopyFile(srcfile, destfile): if not os.path.exists(srcfile): print "%s这个文件不存在或你的文件路径出现错误!" % srcfile if not os.path.exists(destfile): print "%s这个文件不存在或你的文件路径出现错误!" % destfile print "请问是否要重新建立这个文件?(y||n)" if raw_input() == 'y' or raw_input() == 'Y': f = open(destfile, 'w') #建立文件 else: print "文件拷贝创建失败!" f.close() f1 = open(srcfile, 'r') f2 = open(destfile, 'w') while 1: text = f1.read(50) if text == "": break f2.write(text) f1.close() f2.close() return src = raw_input("请输入被拷贝的源文件:\n")dest = raw_input("请输入拷贝到那个文件:\n")MyCopyFile(src, dest)
评论关闭