[Python]代码
#coding:cp936
'''
Created on 2011-6-21
@author: tangly
文件拷贝
'''
import os
def 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)
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8122.html