欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

iPod文本分割器(VBS版)

程序员文章站 2022-08-27 17:01:11
因此暑假闲暇编写了这个简短精悍的脚本版的分割器。脚本版的最大的好处可以由使用者进行diy。 具体情况就不多说了,关于txt编码的问题可以参考,ipod文本分割器 这里仅仅说...

因此暑假闲暇编写了这个简短精悍的脚本版的分割器。脚本版的最大的好处可以由使用者进行diy。
具体情况就不多说了,关于txt编码的问题可以参考,ipod文本分割器
这里仅仅说明使用方法,将您需要分割的txt文件直接拖放发到本脚本上就ok了。
以下是脚本代码,直接复制后保存为vbs文件就可以了!
good luck !

复制代码 代码如下:

'------------------------------------------------------------
' description : text division for ipod text reading.
' because of ipod can not display text length
' more than 4kb in each file, we have to split
' the bigger one.
' and ipod intrenal use unicode, so this script
' can also tranfrom the character coding.
' author : guoyafeng@jspi.edu.cn
' last modified : 2008-8-31 11:05:13
'------------------------------------------------------------
option explicit
sub opendir(dir)
dim wshell,cmdstring
set wshell = createobject("wscript.shell")
cmdstring = "explorer.exe " & dir
wshell.run cmdstring,1,true
end sub
function formatstrnum(inum)
const mode = "0000"
dim snum
snum = cstr(inum)
formatstrnum = left(mode,len(mode)-len(snum)) & snum
end function
function iif(test,a,b)
if test = true then iif = a else iif = b
end function
function getdragdropfile
if wscript.arguments.count = 0 then msgbox "请把需要分割的txt文件拖放到本脚本上!"
wscript.quit
else
dim fso
set fso = createobject("scripting.filesystemobject")
if (fso.fileexists(wscript.arguments(0))) then
getdragdropfile = wscript.arguments(0)
set fso = nothing
else
set fso = nothing
msgbox "无法找到文件" & wscript.arguments(0)
wscript.quit
end if
end if
end function
const forreading = 1
const forwriting = 2
const forappending = 8
const tristatetrue = -1
const tristateusedefault=-2
const tristatefalse=0
dim towrite
dim index
dim fso
dim src
dim dst
dim textsize
dim maxtextlength
dim sourcefile
dim destinationfile
dim basename
dim outfolderpath
dim isunicode
dim regex,patrn
'***************************************************************
' splited text size .
textsize = 4 'kb
isunicode = true
'*****************************************************************
maxtextlength = 1024 * textsize / 2 - 1
patrn = "(\r\n\r\n)+|( +)"
set regex = new regexp
regex.pattern = patrn
regex.ignorecase = true
regex.global = true

set fso = createobject("scripting.filesystemobject")
basename = fso.getbasename(getdragdropfile)
outfolderpath = fso.buildpath(fso.getparentfoldername(getdragdropfile),_
basename)
set src = fso.opentextfile(getdragdropfile, forreading,false,_
tristateusedefault)
if not fso.folderexists(outfolderpath) then
fso.createfolder outfolderpath
end if
index = 1
while(src.atendofstream <> true)
towrite = src.read(maxtextlength)
destinationfile = fso.buildpath(outfolderpath,basename & _
formatstrnum(index) & ".txt")
set dst=fso.opentextfile(destinationfile,forwriting,true,iif(isunicode,tristatetrue,tristateusedefault))
dim slimtext
slimtext = regex.replace(towrite,"")
dst.write slimtext
dst.close
set dst = nothing
index = index + 1
wend
src.close
set src = nothing
set fso = nothing
set regex = nothing
opendir outfolderpath