网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 文本文件分割脚本(VBS)
内容
    在系统维护或者数据库维护是常常需要查看的日志文件,然为日志文件往往都比较大,甚至用记事本无法打开。
    而Windows下没有一个现存的比较好用的分割工具,所以我用VBS做了一个文本文件的分割工具,和各位网友共享。脚本代码如下:
    代码如下:
    Option Explicit
    '这个脚本只用来分割文本文件,脚本需要3个参数
    '参数列表
    '文件名 参数1 参数2
    '梦想工作室 www.mx111.com
    '示例 参数1 参数2 参数意义
    ' S 5 等分为5个文件
    ' E 1024 按照1024的大小分割文件
    ' F 1024 取最前面的1024字节存为一个文件
    ' L 1024 取最后面的1024字节存为一个文件
    Dim tf,sf,fname,souFile,desFolder ,sOption , sNum , FSO , fs, sfs
    If WScript.Arguments.Count < 3 Then
    WScript.Echo "参数有误!"
    WScript.Quit
    Else
    souFile = WScript.Arguments(0)
    sOption = WScript.Arguments(1)
    sNum = WScript.Arguments(2)
    End If
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set tf=FSO.GetFile(souFile)
    fs = tf.Size
    Set tf = fso.OpenTextFile(souFile, 1)
    Dim x
    Select Case sOption
    Case "S"
    sfs = Int ( fs / sNum )
    for x=1 to sNum-1
    SaveSubFile "file_" & x &".txt", 0 ,sfs
    Next
    SaveSubFile "file_" & sNum &".txt", 0 , fs - sfs * (sNum-1)
    Case "E"
    sfs = sNum
    sNum = Int ( fs / sfs) + 1
    for x=1 to sNum-1
    SaveSubFile "file_" & x &".txt", 0 ,sfs
    Next
    SaveSubFile "file_" & sNum &".txt", 0 , fs - sfs * (sNum-1)
    Case "F"
    SaveSubFile "file_" & 0 &".txt", 0 , sNum
    Case "L"
    SaveSubFile "file_" & 0 &".txt", fs - sNum , sNum
    End Select
    tf.Close
    Sub SaveSubFile(s,b,l)
    Dim sfile,content
    WScript.Echo s & ":" & b &":" & l
    Set sfile = fso.CreateTextFile(s, TRUE)
    If b>0 Then
    tf.Skip(b)
    End If
    content = tf.Read(l)
    sfile.Write(content)
    sfile.Close
    End Sub
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/13 12:23:27