当前位置: 移动技术网 > IT编程>脚本编程>VBScript > 文本文件分割脚本(VBS)

文本文件分割脚本(VBS)

2017年12月08日  | 移动技术网IT编程  | 我要评论

切尔西足总杯,维基解密 维基百科,夫妇驾驶途中激情难耐致车祸

而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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网