Script Request - Text-merging Tool.

Discuss and share scripts and script files...
Post Reply
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Script Request - Text-merging Tool.

Post by SkyFrontier »

Can someone please build a text merging tool, which could (out of a file search, for instance, or simple file selection) combine several same named or not text files into a single one, having a separator like this?

Code: Select all

Excerpt 1.

=======================

Excerpt 2.

=======================

Excerpt 3.

=======================

Thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Script Request - Text-merging Tool.

Post by Stefan »

I had this week the need for such an script:

FileConcatenator.xys

Code: Select all

// 2010-11-10 Concatenator: concatenat files
// Step through all files, if ext=txt read the file into an array


//init:
  $ARRAY="";
  $Count=0;

  //Loop infinity:
  while(true)
  {
         // add only files with ".TXT"-extension:
         if("<curext>"=="txt")
         {
             $Count++;
               
              //Info:
              //the $ARRAY is the var to collect all the files,
              //the READFILE will read the file into this array,
              //the STRREPEAT-part will just format the output file and add a few blank lines
         
             $ARRAY = $ARRAY 
                 . readfile("<curname>") 
                 . strrepeat("<crlf>", 5) 
                 . strrepeat("******", 5) 
                 . "<crlf>      <FILE SEPARATOR>  -  <curname><crlf>" 
                 . strrepeat("******", 5)
                 . strrepeat("<crlf>", 5) ;
         }
     
         //try next file:
         sel "+ 1";
            //if there is no more file to add...
            if("<curname>"=="")
            {
                  //if there was at least one file added:
                  if ($Count > 0)
                   { 
                       //then create the collection file:
                       writefile("<curpath>\_alle.txt", "  *** $Count concatenated files, 
                                 separated by <FILE SEPARATOR> ***<crlf><crlf><crlf>$ARRAY"); 
                   }
                   break;
            }
            //ELSE: proceed next file...
  }

EDIT to reflect the script syntax chances from sel +1; to sel "+ 1";
Last edited by Stefan on 27 Jan 2011 09:08, edited 1 time in total.

EDIT adjust a bit the code indent for better view
Last edited by Stefan on 20 Oct 2011 08:09, edited 2 times in total.

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Script Request - Text-merging Tool.

Post by SkyFrontier »

The address bar code I was using in the meantime:

Code: Select all

::writeFile("zzzSEPARATOR.txt", "====End=of=File===SEPARATOR====End=of=File===", o); $a = readfile(<curitem>); copytext $a; writeFile("_MergedText.txt", "<crlf><crlf>$a<crlf><crlf>==================", a, tu); focus; sendkeys'{down}'; focus a; sendkeys"{enter}";
I liked your version of the separator...
Thanks, Stefan!
More reliable than mine...
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Post Reply