数学建模社区-数学中国
标题:
文件合并
[打印本页]
作者:
2744557306
时间:
2024-3-31 17:17
标题:
文件合并
#path='C:\\Users\\test\\IAP_CZ_v204w.hex'
) l- D! a" U# x d% ]. s0 ?$ U1 i
#file=open(path,'r')
8 M/ g% G3 }; L" L$ B& N9 S
#for ll in file.readlines()
2 Y8 } j: @+ V7 z& g6 c6 z) }
# print ll
+ m! P$ Y r2 v; M. Q: l
#coding=gb18030
7 h. d! Z2 J. g, W
import time
% a/ X$ H7 u8 J v" F
import os
; e8 j0 \9 `3 n4 u' F
def prr():
0 y4 ]' R) D/ Z! ~5 b
print 'file combination begin..'
7 i6 @, M2 f# g2 Z$ G' O
, o$ d% D4 J8 h( ?- ]3 L
path0=os.getcwd()
4 U/ ~" h" l9 _1 }! I# R
print path0
u0 B3 d2 p3 Q2 o1 q1 g
path=path0
; o% E7 \7 c: i+ f% h3 A
#path1=path0
R/ D% o; |6 r6 {6 Q
path2=path0
; b8 Y! @6 _. R
path+='\\IAP_CZ_v204w.hex'
o) i, G( G; L2 h7 r1 O( K
#path1+='\\NC_armStaSystem.hex'
* u5 t7 m: ~# m1 j% A( y$ M
path2+='\\'
* e; i. U6 J1 u3 K" v3 S
print path
" G) H1 [. ~3 s. J5 J8 i
s=raw_input('enter file path:')
5 y' h) {+ j' r! J3 T" J
path1=s
5 w# j# q. J& U* g: @8 |) H
#path1+='\\NC_armStaSystem.hex'
7 o& S3 q* N' X+ ^/ Y X, {
print path1
0 e6 I. g5 G2 {6 g! V
s=raw_input('enter file name:')
' p8 V% b! B/ N& [- Y- N$ m5 _2 F
path2+=s
; D! ^ ~$ \2 ?# {3 G
path2+=time.strftime('_%y%m%d%H%M%S')
1 J1 `/ M: a. T
path2+='.hex'
% c- J3 M0 `. E) K$ I
print path2
. o7 j4 D% ] U" _9 ~
prr()
$ H& i2 g, Y: z# ?8 w; p# J& f# R
try:
. H5 Y9 \) E0 j$ _" X
f1=open(path,'r')
6 L8 c K4 U# O) [
count=0
4 {# Y( h [& w2 U+ z
for l in f1.readlines():
0 p$ {& g% D3 y# e7 K
# print l
0 c$ i: H# r, _1 U3 d6 T. q4 T
count+=1
0 h$ X5 P, j1 M" X) t5 ?
#print count
5 l- Y, v; Q8 @ x' s; K' n/ ~
f1.close()
6 O' ~/ I2 \( z' O; B4 B$ J; O
f1=open(path,'r')
6 p2 i, Z+ ^) H! q# U3 I
f2=open(path1,'r')
) r( \) Q% S9 M& a& Z! |
f3=open(path2,'w')
# H/ d, U7 l ^9 G; N
while(count>1):
9 ^0 W; I1 s: M: N+ ~
l=f1.readline()
3 Y) [1 i% G, X1 f
# print l
: U6 _' y) K0 J; W8 {! U
f3.write(l)
$ A: e2 \2 R1 L: P$ }! D3 o. T
count-=1
$ X. X# f9 u A) C3 `" B
# print count
; P; c8 c& d! @5 d8 U
f3.flush()
' O/ d7 \9 y& K: a
for l in f2.readlines():
6 U8 a/ K" {* K9 H) g% d
f3.write(l)
7 s! o: P- W1 t* {* j4 N$ A; n+ A5 t
f3.flush()
5 x7 {% V+ G7 F' d
f3.close()
! X+ v& ?9 s9 b2 V
print 'combination success!'
2 ^8 |( X: e& w+ d( w% S
except Exception,ex:
H/ l- y% T+ ?: w1 c4 q
print 'excettion occured!'
0 ^5 y# i. ?" n5 u; H, T
print ex
: Z2 _; a0 ~2 e7 J. v# J$ H
s=raw_input('press any key to continue...')
0 S2 R$ s( ]2 s, v- f$ C
finally:
) Y8 I2 C, K1 b+ n$ K
f1.close()
0 W8 Q) n" m( x' h: z# V
f2.close()
/ B5 w' X( g0 T. n# ?! }
s=raw_input('press any key to continue...')
% s6 n% p) I4 O0 i h+ b
! X& u$ ~0 ?0 j& ?6 P
3 Z; Y! X. G4 @
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5