
CODE: [Copy to clipboard]@echo off
cls & color 79
setlocal enabledelayedexpansion
:inputfilename
set /p txtfile=请输入要分割的文件位置及文件名:
if not defined txtfile goto :inputfilename
set /p lines=请输入每多少行分割为一个文件(请输入50到300之间的数):
if not defined lines set /a lines=100
cls
set /a line=-1
set /a files=1
set filename=第!files!部分.txt
mode con lines=2
echo 正在写第1个文件...
for /f "delims=" %%i in (%txtfile%) do (
set /a line+=1
if "!line!"=="%lines%" (
set /a line=0
set /a files+=1
set filename=第!files!部分.txt
echo %%i>>!filename!
) else (
echo %%i>>!filename!
)
)
echo 完成。按任意键退出程序...
pause>nul
CODE: [Copy to clipboard]鉴于这确实是频繁操作(写)一个磁盘文件,就是慢~@echo off
color 0a
setlocal enabledelayedexpansion
:inputfilename
set /p txtfilename=请输入要分割的文件位置及文件名:
if not defined txtfilename goto :inputfilename
set /p lset=请输入每多少行分割为一个文件(默认100行):
if not defined lset set /a lset=100
cls
set /a fnumb=1
set /a lnumb=0
set subfdr=%txtfilename:~0,-4%
rd /s /q "!subfdr!" 2>nul
md "!subfdr!"
for /f "delims=" %%i in (%txtfilename%) do (
set filename="!subfdr!"\第!fnumb!部分.txt
echo %%i>>!filename!
set /a lnumb+=1
if !lnumb!==1 (
echo 正在写第!fnumb!个文件...
)
if !lnumb!==%lset% (
set /a tnumb=!tnumb!+!lnumb!
set /a lnumb=0
set /a fnumb+=1
)
)
set /a tnumb=!tnumb!+!lnumb!
echo 共!tnumb!行非空
echo 完成。按任意键退出程序...
pause>nul
CODE: [Copy to clipboard]'''设置每篇字数
oLth=3500'''vb字
set fso=createobject("scripting.filesystemobject")
flpth=inputbox("the file to be splited","split joint.txt","joint.txt")
set fl=fso.opentextfile(flpth)
ctnt=fl.ReadAll
dl=MsgBox("是否符合段前空两格而优化",vbokcancel)
If dl=1 then
ctnt=Replace(ctnt,vbcrlf&" ",vbcrlf&"ㄓ")
ctnt=Replace(ctnt,vbcrlf&" ",vbcrlf&"ㄓ")
ctnt=Replace(ctnt," ","")
ctnt=Replace(ctnt," ","")
ctnt=Replace(ctnt,"ㄓ",vbcrlf&" ")
for i=1 to 5
ctnt=Replace(ctnt,vbcrlf&vbcrlf&vbcrlf&vbcrlf,vbcrlf)'''n-1=i times
ctnt=Replace(ctnt,vbcrlf&vbcrlf,vbcrlf)
next
End if
fl.Close
Tlth=Len(ctnt)
If Tlth<oLth Then
MsgBox("已达要求")
else
newn=fso.GetBaseName(flpth)
extn=fso.GetExtensionName(flpth)
Tct=Tlth\oLth+1
n=0
Do
n=n+1
If Tct>=10^(n-1) And Tct<10^n Then Bct=n:Exit Do
Loop
Set fl=fso.GetFile(flpth)
Set bfdr=fso.GetFolder(fl.ParentFolder)
If fso.FolderExists(bfdr&"\"&newn)=true Then
Set fdr=fso.getFolder(bfdr&"\"&newn)
else
Set fdr=fso.CreateFolder(bfdr&"\"&newn)
End If
For i=1 To Tct
strt=oLth*(i-1)+1
ct=String(n-Len(i),"0")&i
Set fl=fdr.CreateTextFile(ct&"."&extn)
newf=Mid(ctnt,strt,oLth)
fl.write newf
fl.close
Next
End If
MsgBox("Done.分了"&Tct&"个文件.")
| 欢迎光临 中国DOS联盟论坛 (http://cndos.fam.cx/forum/) | Powered by Discuz! 2.5 |