| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
LasonyaHart
9年前发布

Python文件拷贝

[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)