Batch to Split TXT Files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Stenio
Posts: 1
Joined: 10 Apr 2020 09:11

Batch to Split TXT Files

#1 Post by Stenio » 10 Apr 2020 09:14

Hi Everyone

I Have 1 file TXT with 1000 lines of DATA. I would link use batch script to split this Text Files intro 5 Files with 200 lines each. Can You Help-me?

Thanks a lot

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: Batch to Split TXT Files

#2 Post by Hackoo » 12 Apr 2020 07:02

Hi :wink:
I already posted a solution here : [Batch] Split a .txt file into a batch file ; and you can easily edit just one line in this variable : Limit_Line_Counter

Code: Select all

@echo off
Title A batch splitting text Script by Hackoo 2020
Color 0A
set "Limit_Line_Counter=200" REM You can modify and edit just this line
set "InputFile=%1"
If "%~x1" NEQ ".txt" Goto :Help
set "lineCounter=1"
set "filenameCounter=1"
SetLocal EnableDelayedExpansion

@for %%a in (%InputFile%) do (
	set "name=%%~na"
	set "extension=%%~xa"
	@for /L %%i in (1,1,100) Do (
		If Exist "!name!%%i!extension!" Del "!name!%%i!extension!"
	)
)

@for /f "tokens=*" %%a in (%InputFile%) do (
	set "splitFile=!name!!filenameCounter!!extension!"
	set /a lineCounter+=1
	if !lineCounter! GTR !Limit_Line_Counter! (
		set /a filenameCounter+=1
		set lineCounter=1
		echo Created !splitFile!
	)
echo %%a>>!splitFile!
)
Timeout /T 3 /nobreak>nul & Exit
::------------------------------------------------------------------
:Help
Color 0C & Mode 80,3
echo(
echo       Usage : Drag and Drop a txt file over this script:"%~nx0"  
Timeout /T 5 /nobreak>nul & Exit
::------------------------------------------------------------------

Post Reply