Append/Combine/Merge Text files
Moderators: Hacker, petermad, Stefan2, white
- AnthonyCian
- Senior Member
- Posts: 265
- Joined: 2005-06-16, 01:45 UTC
- Location: Thatcher Az. USA
Append/Combine/Merge Text files
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
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
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
A batch script would do it
ButtonBar: SomeIcon
(or somewhere within your %PATH%)
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
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.
ButtonBar: SomeIcon
Save this to C:\WINNT\System32\MergeFiles.cmdCommand: cmd /c mergeFiles.cmd
Parameters: %S
(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%
File1 thru File3 will be appended to File0.txt
You could also change the following on the buttonBar
This will also work, if you select files while DirBranch is active.Command: cmd /c MergeFiles.cmd "NameOfMasterFile.txt"
Parameters: %S
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.
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
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%"
)
- AnthonyCian
- Senior Member
- Posts: 265
- Joined: 2005-06-16, 01:45 UTC
- Location: Thatcher Az. USA
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
Hehe yer welcome 
How I have it running, I have that last posts' code in:
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.

How I have it running, I have that last posts' code in:
I have an Icon on my ButtonBar that has:C:\WINNT\System32\MergeFiles.cmd
The Icon stuff is irrelevant, obviously.Command: cmd /c mergeFiles.cmd
Parameters: %S
Icon file: %APPDATA%\GHISLER\GUI\icons\Mix0510.icl
Icon: 23
Tooltip: Merge Selected Files
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.
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
Here's an updated MergeFiles.cmd.
Re: Append/Combine/Merge Text files
Hi Anthony.AnthonyCian wrote: *A third party program that can be suggested?
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!
