I don't have such a large file to evaluate if UE v22.0.0.66 can copy a larger block via clipboard to a new file. But I don't think so as also UE v22 is still a 32-bit application. What is the maximum number of bytes for being copied depends on
- architecture of application: x86 or x64
- application was coded to handle addresses larger than 2 GB linked with large address aware option, see Wikipedia article about x86-64
- and what is the largest free block in memory accessible by the application.
The last point is what an application can't really control and what finally determines the largest block which can be copied at once. For example it does not help if there are 1.5 GB of free memory in total for an x86 non large address aware application remaining, but the total accessible 2 GB is fragmented by several memory allocations and memory frees already in several smaller free blocks. It might be helpful to restart Windows to have memory usage reduced to minimum, then start UltraEdit and run the script for splitting up the file.
But much better would be to edit the script and use following enhanced version of the script splitting a huge file into several large files
(tested only on a small file).
Code: Select all
// First file (most left on file tabs bar) must be the file to split.
if (UltraEdit.document.length > 0) { // Is any file opened?
// Set number of lines per block and number of blocks per file here!
// Number of lines per file = nLinesPerBlock * nBlocksPerFile
var nLinesPerBlock = 100000;
var nBlocksPerFile = 5;
var bCopyFirstLine = false; // Copy first line into every file.
var nNextLineNum = nLinesPerBlock + 1;
var nFileCount = 0;
// Define the environment for the script.
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.document[0].hexOff();
// Move caret to top of the file.
UltraEdit.document[0].top();
if (bCopyFirstLine) {
// Code to copy first line of file into user clipboard 8 for pasting
// it later into every file created on splitting the large file.
UltraEdit.selectClipboard(8);
UltraEdit.document[0].selectLine();
UltraEdit.document[0].copy();
UltraEdit.document[0].cancelSelect();
UltraEdit.document[0].gotoLine(2,1);
nNextLineNum++;
}
UltraEdit.selectClipboard(9);
// Quick and dirty solution to get file name without extension
// and the file extension. Does not work for all file names.
var nLastPoint = UltraEdit.document[0].path.lastIndexOf('.');
if (nLastPoint < 0) nLastPoint = UltraEdit.document[0].path.length;
var sFileName = UltraEdit.document[0].path.substr(0,nLastPoint) + '_';
var sFileExt = UltraEdit.document[0].path.substr(nLastPoint);
while (1) {
UltraEdit.document[0].gotoLineSelect(nNextLineNum,1);
if (!UltraEdit.document[0].isSel()) break;
// Copy the selected block to user clipboard 9.
UltraEdit.document[0].copy();
UltraEdit.document[0].cancelSelect();
UltraEdit.newFile();
// New files are always created with a temporary file independent on
// what is selected in configuration for usage of temporary files as
// a new file is not yet saved with a name in a specified directory.
// This means also the undo feature is always enabled for new files.
// Save the still empty new file with right name, close the file and
// immediately open it again. If option "Open file without temp file
// but NO Prompt" is selected at "Advanced - Configuration - File
// Handling - Temporary Files" with a threshold value of 0, the new
// file is opened now without usage of a temporary file which means
// without Undo feature enabled for this file making it faster
// copying and pasting large blocks into this new file.
nFileCount++;
var sFileNameWithPath = sFileName + nFileCount + sFileExt;
UltraEdit.saveAs(sFileNameWithPath);
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
UltraEdit.open(sFileNameWithPath);
if (bCopyFirstLine) {
// Paste the first line first into the new file.
UltraEdit.selectClipboard(8);
UltraEdit.activeDocument.paste();
UltraEdit.selectClipboard(9);
}
// Paste the file copied block into the new file.
UltraEdit.activeDocument.paste();
// Copy up to 4 more blocks from input file to current new file.
// Each new file contains than 500.000 lines if input file has
// enough lines remaining.
for (var nBlock = 1; nBlock < nBlocksPerFile; nBlock++ )
{
nNextLineNum += nLinesPerBlock;
UltraEdit.document[0].gotoLineSelect(nNextLineNum,1);
if (!UltraEdit.document[0].isSel()) break;
UltraEdit.document[0].copy();
UltraEdit.document[0].cancelSelect();
UltraEdit.activeDocument.paste();
}
// Close the file with saving although if empty file was really
// opened without usage of a temporary file each paste was directly
// written to storage media and therefore the file does not need
// to be explicitly saved because everything is saved already.
UltraEdit.closeFile(UltraEdit.activeDocument.path,1);
nNextLineNum += nLinesPerBlock;
}
UltraEdit.document[0].top();
// Clear the used user clipboards and reselect system clipboard.
UltraEdit.clearClipboard();
if (bCopyFirstLine) {
UltraEdit.selectClipboard(8);
UltraEdit.clearClipboard();
}
UltraEdit.selectClipboard(0);
UltraEdit.messageBox(nFileCount + " files created.");
}
This script copies just 100.000 lines via clipboard to the output files. But up to 5 blocks each with 100.000 lines are copied now into one output file before next output file is created. This has the advantage that a smaller free memory block must be available in accessible RAM for UltraEdit than when trying to copy 500.000 lines at once from opened file to split into each output file.
But there is one problem left if the output files should be several hundred MB. A new file is always created with usage of a temporary file. This means copying several large blocks results in allocating several large blocks in memory for the undo feature which could easily result again in an out of memory condition.
But there is a workaround for this problem.
The configuration option
Open file without temp file but NO Prompt must be selected at
Advanced - Configuration - File Handling - Temporary Files and
0 must be set for
Threshold for above (KB). The script saves now each new file immediately after creation, closes it and re-opens the just created new output file. Now the output file is opened without usage of a temporary file which means also with undo feature disabled for this file, too. Copying and pasting the up to 5 x 100.000 lines is done now without recording anything for undo feature.
And additionally on final close of each output file, UltraEdit does not need to copy the large amount of data from temporary file to final location of output file as there is no temporary file. This should make splitting a huge file into several still very large files faster decreasing total script execution time.