set /a n=101600,kb=n
set "临时文件=tmp.txt"
set /p file=请把要处理的文件拖到此处:
set "file=%file:"=%"
cls&echo 正在分割 %file% 文件请稍候。。。
for /f "delims=" %%a in ("%file%") do set wjm=%%~na
findstr /no ".*" "%file%">"%临时文件%"
for /f "tokens=2 delims=:" %%a in ('find /c /v "" "%临时文件%"') do set /a z=%%a
if not exist "%wjm%\" md "%wjm%"
:list
set /a x+=1
if defined t >>"%wjm%\%wjm%_%x%.txt" echo %t%
set "t="
if not defined h (set skip=) else (set skip=skip=%h%)
setlocal enabledelayedexpansion
for /f "%skip% tokens=1,2* delims=:" %%a in (%临时文件%) do (
if %%b geq !kb! set /a kb+=n&set flag=a&goto loop
set /a g+=1
set !g!=%%c&set /a h=%%a,u=%%a
)
:loop
if not defined flag (
if defined t >>"%wjm%\%wjm%_%x%.txt" echo %t%
for /l %%a in (1 1 !g!) do >>"%wjm%\%wjm%_%x%.txt" echo.!%%a!
goto end
)
set "var=!%g%!"
if not defined var set /a g-=1,h-=1&goto loop
for /f "tokens=1* delims=。" %%a in ("!var!") do (
if "!var!"=="%%a" set /a g-=1,h-=1&goto loop
if not "%%b"=="" set "t=%%b"
set w=%%a。
)
for /l %%a in (1 1 !g!) do >>"%wjm%\%wjm%_%x%.txt" echo.!%%a!
>>"%wjm%\%wjm%_%x%.txt" echo !w!
endlocal&set h=%h%&set t=%t%&set kb=%kb%&set "u=%u%"
if %u% neq %z% goto list
:end
del/q "%临时文件%" 2>nul
start "" "%wjm%"
@echo off & title 分割文本 By 依梦琴瑶setlocal enabledelayedexpansion
::设置要分割的文件
set file=test.txt
for /f "delims=" %%a in ('type "%file%"') do (
echo "%%~a" | findstr ^"\^> >nul && (
for /f "tokens=2 delims=> " %%b in ('echo "%%~a"') do set "txt=%%~b.txt"
) || (
(echo %%~a)>>"!txt!"
)
)
pause
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)