Page 1 of 1

Script Request - Text-merging Tool.

Posted: 26 Sep 2010 21:41
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!

Re: Script Request - Text-merging Tool.

Posted: 14 Nov 2010 01:59
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

Re: Script Request - Text-merging Tool.

Posted: 16 Nov 2010 03:42
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...