Import OS import sys import string #以指定模式打开指定文件 get file handle def getfileins (Filepath,model): print (open file) print (fi
Lepath) print (model) return open (Filepath,model) #获取需要处理的文件 def getprocfile (path): Return Os.listdir (PATH)
#判断是否满足某个条件, if satisfied then execute def isTrue (outfileins,s): findStr1 = "Line_count_update INTEGER: = 0;" WRITESTR1 = "Line_count_error INTEGER: = 0; --Error data xx strip "FINDSTR2 =" dbms_output. Put_Line (' finished "WRITESTR2 = Dbms_output. Put_Line (' Error data ' | | line_count_error| | ']
article. '); FINDSTR3 = "Dbms_output." Put_Line (' Insert data [' | | cur_result.int_id| | ']
When an exception occurs ... ');
WRITESTR3 = "Line_count_error: = line_count_error+1;" FINDSTR4 = "Dbms_output." Put_Line (' Update data [' | | cur_result.int_id| | ']
When an exception occurs ... ');
If S.find (FINDSTR1)!= -1:outfileins.write (s) outfileins.write (writestr1+ "\ n") elif S.find (FINDSTR2)!=-1:
Outfileins.write (s) outfileins.write (writestr2+ "\ n") elif S.find (FINDSTR3)!= -1:outfileins.write (s) OutfileinS.write ("\t\t\t\t" +writestr3+ "\ n") elif S.find (FINDSTR4)!= -1:outfileins.write (s) outfileins.write ("\t\t\t\ t\t "+writestr3+") elif s.find ("Cs_oslgis")!= -1:outfileins.write (S.replace ("Cs_oslgis", "CQ_RMW") elif s.f IND ("and A.longitude >")!= -1:outfileins.write ("\t\t\tand a.longitude is not null\n\t\t\tand a.longitude are not Null\n\t\t\tand rownum<2\n ") elif s.find (") LOOP ")!= -1:outfileins.write (" \t\t) loop\n ") Else:outfil Eins.write (S.replace ("| | |") ', 2 "," | | | ') ', 3 ")) #读取并处理文本 def getandproc (infileins,outfileins): lines = Infileins.readlin ES () for S in lines: #print (s) isTrue (outfileins,s) if __name__== "__main__": Infilemod = "R" Out Filemod = "W" path = "D:\\rmsdata2gis" for Tmpfile in Os.listdir (path): Infilepath = path+ "\" +tmpfile out FilePath = path+ "\\BAK_" +tmpfile infileins = Getfileins (infilepath,infilemod) outfileins = Getfileins (outfilepat H,OUTFILEMOD) GetanDproc (Infileins,outfileins) infileins.close () Outfileins.close ()