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)
本文由用戶 LasonyaHart 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!