See Function to get list of files into an edit window
for function GetListOfFiles
and how to use it to run a script on all files of a directory or directory tree matching a file name pattern.
There are the topics Sort by line (column) length
(old macro solution) and Goto longest line
(newer scripting solution).
It would be also possible to code a script which runs Perl regular expression Find in Files (from a high length value to lower length values until longest line found) to determine the longest line in a set of files.
- Code: Select all
if (UltraEdit.document.length > 0) // Is any file opened?
var nMaximumLineLength = 0;
// Define environment for this script.
// Determine type of line termination (DOS/UNIX/MAC).
var sLineTerm = "\r\n";
if (UltraEdit.activeDocument.lineTerminator == 1) sLineTerm = "\n";
else if (UltraEdit.activeDocument.lineTerminator == 2) sLineTerm = "\r";
// Get all lines from active file into memory as an array of strings
// and compare the number of characters of each line with the current
// maximum value to get finally the length of the longest line in file.
if (UltraEdit.activeDocument.isSel()) // Is the file not empty?
var asLines = UltraEdit.activeDocument.selection.split(sLineTerm);
for (var nLine = 0; nLine < asLines.length; nLine++)
if (asLines[nLine].length > nMaximumLineLength)
nMaximumLineLength = asLines[nLine].length;
UltraEdit.activeDocument.top(); // Cancels the selection.
UltraEdit.messageBox("Maximum line length is: " + nMaximumLineLength);
If the file contains horizontal tabs and the tab stop value must be taken into account on determining the length of longest line in a file, non of the scripting solutions work as they all work with the number of characters within a line and not with length of line as displayed in UltraEdit taking horizontal tabs and tab stop value(s) into account.