Hi,
It been sooo long since the last time I visit this forum.
I have a text file consisting of few hundreds line of text. I need to save each line to a new file and name it based on the line number.
Pls advise.
Thanks,
Welcome to the IDM Forum. This forum is meant as a user-to-user support mechanism where users can share knowledge and tips for all IDM software.
Since these forums are user-to-user based, IDM does not regularly read or reply to the posts in this forum. For problem reports, suggestions, or feature requests, you must email us directly. Our trained technical support staff answers most inquiries within 30 minutes.



// Set working environment required for this script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.activeDocument.hexOff();
UltraEdit.ueReOn();
UltraEdit.selectClipboard(9);
var ActFileIndex = getActiveDocumentIndex();
if (ActFileIndex >= 0) SaveLinesIntoFiles(ActFileIndex); // If any file is open!
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
// End of script!
// Main function which saves every not empty line into a file with line number as file name.
function SaveLinesIntoFiles(SourceFileIndex) {
var LineNumber = 1;
// Check if current file is empty file because nothing to do on an empty file.
UltraEdit.document[SourceFileIndex].bottom();
var ColumnNumber = UltraEdit.document[SourceFileIndex].currentColumnNum;
if (typeof(UltraEdit.activeDocumentIdx) == "undefined") ColumnNumber++;
if ((UltraEdit.document[SourceFileIndex].currentLineNum < 2) && (ColumnNumber < 2)) return;
// Make sure last line of file has a line termination.
if (UltraEdit.document[SourceFileIndex].isColNumGt(1)) {
UltraEdit.document[SourceFileIndex].insertLine();
}
UltraEdit.document[SourceFileIndex].top();
while (!UltraEdit.document[SourceFileIndex].isEof()) {
// Copy only lines with characters, not empty lines.
UltraEdit.document[SourceFileIndex].startSelect();
UltraEdit.document[SourceFileIndex].key("END");
if (UltraEdit.document[SourceFileIndex].isSel()) {
UltraEdit.document[SourceFileIndex].copy();
UltraEdit.newFile();
UltraEdit.activeDocument.paste();
UltraEdit.activeDocument.insertLine();
UltraEdit.saveAs("F:\\Temp\\"+LineNumber+".txt");
UltraEdit.closeFile(UltraEdit.activeDocument.path,0);
}
UltraEdit.document[SourceFileIndex].endSelect();
UltraEdit.document[SourceFileIndex].gotoLine(++LineNumber,1);
}
/* Following line is only useful if more than 1 file is open, the active
file on script start was not the most right one and config setting
>Move to nearest left tab after current tab is closed< is enabled. */
UltraEdit.document[SourceFileIndex].setActive();
UltraEdit.document[SourceFileIndex].top();
}
/* Find the tab index of the active document.
Copied from forum topic: Get Active Document's Index
http://www.ultraedit.com/forums/viewtopic.php?t=4571 */
function getActiveDocumentIndex() {
var tabindex = -1; /* start value */
for (i = 0; i < UltraEdit.document.length; i++)
{
if (UltraEdit.activeDocument.path==UltraEdit.document[i].path) {
tabindex = i;
break;
}
}
return tabindex;
}