Plugin to merge/combine files?

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Plugin to merge/combine files?

Post by *Peter »

I have to merge/combine text-files very often. Is there a (packer?)-plugin to select files and then concatenate them?

Peter
TC 10.xx / #266191
Win 10 x64
hi5
Power Member
Power Member
Posts: 551
Joined: 2012-11-03, 11:35 UTC
Contact:

Post by *hi5 »

You can do that already if you rename your files first using [C] and then use Files, Combine files it will automatically merge 1.txt and all ascending filenames (2.txt 3.txt 4.txt etc) to one file.

Edit: If the order doesn't matter at all and you want to merge all *.txt files in the current dir you can use a batch file or type in the command bar: copy *.txt /b > mergedfile
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

Hello hi5

thanks, but these are exactly the procedures I currently use and which I want to avoid:
- Rename and merge destroys the original filenames (copy them to a temp-folder is one step more), and
- "copy ..." is less flexible in file selection.

Peter
TC 10.xx / #266191
Win 10 x64
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Post by *milo1012 »

You can use RegXtract for this.

Just use the default values (.* and $0) an enable Search and Replace.
You could also enable dotall to speed up things a little.

Now set the outfile extension accordingly and the files get merged in the order of input,
which is the current Total Commander sort settings for the active pane (by name, date, ...custom columns...).
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

milo1012 wrote:You can use RegXtract for this...
Thanks - exactly what I wanted.

Peter
TC 10.xx / #266191
Win 10 x64
User avatar
Hacker
Moderator
Moderator
Posts: 13065
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

Peter,
It should suffice to add a new extension, .001, .002, etc., so the Extension field in the MRT would look like this:

Code: Select all

[E].[C:3]
Then select the first file and choose Combine Files from the Files menu.

HTH
Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

Hi Roman

thanks, but I tried already the plugin mentioned above, and it works fine. I will use it the next time.

Peter
TC 10.xx / #266191
Win 10 x64
User avatar
Stefan2
Power Member
Power Member
Posts: 4158
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Plugin to merge/combine files?

Post by *Stefan2 »

Peter wrote:I have to merge/combine text-files very often. Is there a (packer?)-plugin to select files and then concatenate them?

Peter
Just with plain PowerShell

Code: Select all

TOTALCMD#BAR#DATA
powershell 
-command $out=""""""; foreach($file in dir *.txt){$out += """Content of $file`r`n`r`n""" + [System.IO.File]::ReadAllText($file, [System.Text.Encoding]::Default ) + """`r`n`r`n##### EOF #####`r`n`r`n"""}; $out | out-file _outfile.txt
%Commander_Path%\WCMICONS.DLL,6
PowerShell Merge TXT files to _outfile.txt


-1

This will result in something like:
_outfile.txt wrote: Content of D:\rive\path\abc.txt

abc
abc
abc

##### EOF #####

Content of D:\rive\path\opq.txt

opq
opq
opq

##### EOF #####

Content of D:\rive\path\xyz.txt

xyz
xyz
xyz

##### EOF #####
- - -

Note:

we can shorten that command to

-command $o=""""""; foreach($f in dir *.txt){$o += """Content of $f`r`n`r`n""" + [IO.File]::ReadAllText($f, [Text.Encoding]::Default ) + """`r`n`r`n##### EOF #####`r`n`r`n"""}; $o | out-file _outfile.txt

and you can drop ", [Text.Encoding]::Default " if you work with plain ASCII 7-bit only.


- - -

Note:

for use with TC I had to escape the quote chars: " > """

If I had used the un-escaped quotes like

Code: Select all

TOTALCMD#BAR#DATA
powershell -NoExit
-command $out=""; foreach($file in dir *.txt){$out += "Content of $file`r`n`r`n" + [System.IO.File]::ReadAllText($file, [System.Text.Encoding]::Default ) + "`r`n`r`n##### EOF #####`r`n`r`n"}; $out | out-file _outfile.txt
%Commander_Path%\WCMICONS.DLL,6
PowerShell Merge TXT files to _out.txt


-1
I get an error like

Code: Select all

Sie müssen auf der rechten Seite des Operators "=" einen Wertausdruck angeben.
Bei Zeile:1 Zeichen:6
+ $out= <<<< ; foreach($file in dir *.txt){$out += Content of $file`r`n`r`n + [Syst
m.Text.Encoding]::Default ) + `r`n`r`n##### EOF #####`r`n`r`n}; $out | out-file _ou
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordExcepti
    + FullyQualifiedErrorId : ExpectedValueExpression


I wish TC had an -RAW parameter.
hi5
Power Member
Power Member
Posts: 551
Joined: 2012-11-03, 11:35 UTC
Contact:

Post by *hi5 »

For reference: http://www.ghisler.ch/board/viewtopic.php?t=28063 (using TCBL or a simple batch script) If you happen to be a AutoHotkey user you can use that too. TCBL can be found here http://www.ghisler.ch/board/viewtopic.php?t=9374
F4MiniMenu (Forum) - Open selected file(s) from TC in defined editor(s) - A (minimalistic) clone of F4Menu
Source at GitHub (AutoHotkey). TCSyncComments (copy file comments)
Post Reply