Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement text File Segmentation script by VBS

Shulou Source: shulou.com Published: 2022-06-03 06:48:14 11月15日 Update

This article is about how VBS implements text file splitting scripts. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

And Windows does not have an existing better segmentation tool, so I used VBS to do a text file segmentation tool, and you share. The script code is as follows:

The code is as follows:

Option Explicit

'This script is only used to split text files, the script requires 3 parameters

'Parameter list

'File name Parameter 1 Parameter 2

'Example Parameter 1 Parameter 2 Parameter Meaning

' S 5 is divided into 5 files

' E 1024 Split file by size of 1024

' F 1024 Take the first 1024 bytes and save them as a file

' L 1024 Take the last 1024 bytes and save them as a file

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

Thank you for reading! About "VBS how to achieve text file segmentation script" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: Files parameters scripts text code content bytes tools more articles good practical size meaning file name article see knowledge examples etc. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information Huawei Redmi Shulou Tech Info