#4021
Yutaka Emura
Keymaster

Here is JavaScript macro to split the currently active file by the same number of lines, in this case, 1000 lines. You can change it to any number of lines. The result files will be saved as “1.txt”, “2.txt”, “3.txt”, … in this folder. As you see in the comment, you might need to set the root folder, in this case C:Test, and this folder must already exist. I hope this helps!


if( !editor.EnableTab ){
editor.EnableTab = true;
alert( "Please run this macro again." );
Quit();
}

sPath = "C:Test"; // Set the root folder where you want to save the split files. It must already exist.
// The result files will be save as "1.txt", "2.txt", "3.txt", ... in this folder.
// If the same file names already exist, these files will be overwritten!
i = 1;
Redraw = false;
while( 1 ) {
docSearch = editor.ActiveDocument;
editor.NewFile();
docResult = editor.ActiveDocument;
docSearch.Activate();
docSearch.selection.StartOfDocument();
docSearch.selection.LineDown( true, 1000 ); // Number of lines for each split file to contain
sLine = docSearch.selection.Text;
if( sLine == "" ){
docResult.Close();
break;
}
docSearch.selection.Delete(1);
docResult.Activate();
docResult.selection.Text = sLine;
docResult.Save( sPath + i + ".txt" );
i++;
docResult.Close();
docSearch.Activate();
}
Redraw = true;

:-)