Append/Combine/Merge Text files

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
AnthonyCian
Senior Member
Senior Member
Posts: 265
Joined: 2005-06-16, 01:45 UTC
Location: Thatcher Az. USA

Append/Combine/Merge Text files

Post by *AnthonyCian »

HI,

Using TC v7.04a under XP Pro

I have mutiple text files that I like to append to one master txt file. I tried the following and all works ok:

*TC Combine feature (trick).
*TC Copy/Append feature - but this has a limit of appending files one at a time.
*The dos command copy/append + + +.

What I like to know is:
*Is there a TC plugin for this?
*A third party program that can be suggested?

Just checking to make sure I haven't missed a better way of doing this huge upcoming project.

Thanks,
Anthony
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

A batch script would do it
ButtonBar: SomeIcon
Command: cmd /c mergeFiles.cmd
Parameters: %S
Save this to C:\WINNT\System32\MergeFiles.cmd
(or somewhere within your %PATH%)

Code: Select all

@ECHO OFF
:: MergeFiles.cmd
:: 1st Argument is the name of the new File
:: All other Arguments the files to be appended to Master. 

SET MASTER=%1
IF NOT EXIST "%1" ECHO. >> %MASTER%
:_LOOP
SHIFT 1
IF NOT "%~1" == "" (
	COPY /A /Y "%MASTER%"+"%1" "%MASTER%"
	GOTO:_LOOP
)
ECHO. >> %MASTER%
Example: Select File0.txt File1.txt File2.txt File3.txt in TC, and PressTheButton.
File1 thru File3 will be appended to File0.txt

You could also change the following on the buttonBar
Command: cmd /c MergeFiles.cmd "NameOfMasterFile.txt"
Parameters: %S
This will also work, if you select files while DirBranch is active.

Caveat(s),
1) If you do the latter, giving a "NameOfMasterFile" that doesn't exist, a file will be created, the file will begin with 1 blank line.
2) One extra blank line at the very end of the Master file is added: to get rid of a possible non-truncated final line.
Last edited by Balderstrom on 2009-07-26, 23:57 UTC, edited 1 time in total.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Addenum: I would implement this so it doesn't require the Empty new file to exist (and be selected), and doesn't require the NameOfMasterFile in the Button command:

Code: Select all

@ECHO OFF
:: MergeFiles.cmd
:: %Arg1%__MERGED.EXT is the name of the new Master File 
:: All other Arguments are appended to Master 

:: Uncomment the next line to provide final filename
:: SET GetFileName=1
SET UnderScore=_
SET isDir="%~a1"
SET isDir=%isDir:~1,1%
IF "%isDir%"=="d" (
	ECHO Select Files only... Exiting.
	GOTO:EOF
)
:_RENAME_MASTER
SET Master=%~n1%UnderScore%_MERGED%~x1
IF EXIST "%Master%" (
	SET UnderScore=_%UnderScore%
	GOTO:_RENAME_MASTER
)

COPY /Y "%~1" "%Master%"
SHIFT 1

:_LOOP
IF NOT "%~1" == "" (
	COPY /A /Y "%Master%"+"%1" "%Master%"
	SHIFT 1
	GOTO:_LOOP
)
ECHO. >> %Master%

:_GET_FILENAME
IF "%GetFileName%"=="1" (
	SET /P Result=New File Name?
	IF EXIST "%Result%" (
		ECHO File Already Exists!
		GOTO:_GET_FILENAME
	)
	MOVE "%Master%" "%Result%"
)
User avatar
AnthonyCian
Senior Member
Senior Member
Posts: 265
Joined: 2005-06-16, 01:45 UTC
Location: Thatcher Az. USA

Post by *AnthonyCian »

Thanks Balderstrom for taking the time to reply and coming up with the scripts.

I don't know if I can set this up, but it is a challenge, and I will try my darness to see if I can. I really like to see how this will work with the project I have in mind.

Again thanks!!!

Anthony
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Hehe yer welcome :-)

How I have it running, I have that last posts' code in:
C:\WINNT\System32\MergeFiles.cmd
I have an Icon on my ButtonBar that has:
Command: cmd /c mergeFiles.cmd
Parameters: %S
Icon file: %APPDATA%\GHISLER\GUI\icons\Mix0510.icl
Icon: 23
Tooltip: Merge Selected Files
The Icon stuff is irrelevant, obviously.

While testing a couple quirks initially, the "Command:" was: cmd /k mergeFiles.cmd
(which keeps the window from closing when its done)

And I have removed the 2 colons from the "SET GetFileName=1" line.

So when the merges are done, the command window will display: New File Name?
So I can type in what the merged file should be called.

I had messed about with it, allowing directories to be selected initially... as it would work on the very first one. But you wind up having to do recursive calls of opening subdirs, and "arrays" of TempFiles - it got messy. So I just prevented Directory selection instead. Since you can just select files while using DirBranch.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Here's an updated MergeFiles.cmd.
cubic
Junior Member
Junior Member
Posts: 82
Joined: 2007-07-18, 12:21 UTC

Re: Append/Combine/Merge Text files

Post by *cubic »

AnthonyCian wrote: *A third party program that can be suggested?
Hi Anthony.

I use this dedicated program: Disk Tools.

You just navigate to the folder where your files are, define a file type filter (like *.txt) and press the big button.
That's it!
:)
Post Reply