标签:style blog http color os io 文件 数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ‘Author: zhangbo2012@outlook.com‘------------------------------------------------------------------------‘修订记录‘20140801 创建‘------------------------------------------------------------------------Dim fsoSet fso = CreateObject("Scripting.Filesystemobject")Dim wshSet wsh = createobject("wscript.shell")Dim isdebugisdebug = 1Const error = "[error]"Const info = "[info]"Const alert = "[alert]"log "START",alertcutfile "清理数据汇总1.txt",50000,".csv",1log "OVER",alert‘-------------------------------------------‘cutfile(file,cutline,filetype,hastitle)‘file 需要处理的文件名‘cutline 拆分行数,如50000‘filetype 输出文件类型,如.csv‘hastitle 源文件中是否包含标题,如果包含‘ 则新创建的文件也会带有标题行‘-------------------------------------------Function cutfile(file,cutline,filetype,hastitle) If not fso.FileExists(file) then log file & " is not exists!",error exit function End If Set rf=fso.opentextfile(file,1) If hastitle then title = rf.readline line_cursor=1 file_cursor=0 Set wf=fso.createtextfile(file & "_" & file_cursor & filetype) wf.writeline title Do While rf.atendofstream=0 wf.writeline rf.readline line_cursor = line_cursor + 1 If line_cursor mod cutline = 0 then log "resolved " & line_cursor,info wf.close file_cursor = file_cursor + 1 Set wf=fso.createtextfile(file &"_" & file_cursor & filetype) wf.writeline title log "building " & file &"_" & file_cursor & filetype,info End If Loop End FunctionFunction log(str,level) If not(level = info and isdebug=0) then wscript.echo level & "|" & Formattime & "|" & str End ifEnd FunctionFunction Formattime() Formattime = year(date) & string(2-len(month(date)),"0") & month(date) & string(2-len(day(date)),"0") & day(date) & string(2-len(hour(time)),"0") & hour(time) & string(2-len(Minute(time)),"0") & Minute(time) & string(2-len(Second(time)),"0") & Second(time)End Function |



VBS实现文本文件按行数拆分的脚本,布布扣,bubuko.com
标签:style blog http color os io 文件 数据
原文地址:http://www.cnblogs.com/zhangbo2012/p/84d3ad70c91fde889d4b2a211073f538.html