That script was very easy to write.
- Code: Select all
if (UltraEdit.document.length > 0) { // Is any file currently opened?
// Define environment for the script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.activeDocument.selectAll();
if (UltraEdit.activeDocument.isSel()) { // Is active file not an empty file?
// Determine line termination.
var sLineTerm = "\r\n";
if (UltraEdit.activeDocument.lineTerminator == 1) sLineTerm = "\n";
else if (UltraEdit.activeDocument.lineTerminator == 2) sLineTerm = "\r";
// Get all lines with the search strings into an array of strings.
var asSearchStrings = UltraEdit.activeDocument.selection.split(sLineTerm);
UltraEdit.activeDocument.cancelSelect();
// Ask script user for directory path.
var sDirectory = UltraEdit.getString("Please enter full directory path:",1);
// If no directory path is entered, use current working directory of UltraEdit.
// If directory path is entered, make sure it ends with a backslash.
if (!sDirectory.length) sDirectory = ".\\";
else if (sDirectory.match(/\\$/) == null) sDirectory += "\\";
// Set the entered directory as root directory for the finds.
UltraEdit.frInFiles.directoryStart=sDirectory;
// Define the other parameters for the multiple Find in Files.
UltraEdit.frInFiles.filesToSearch=0; // Search in a directory
UltraEdit.frInFiles.searchSubs=true; // and all subdirectories.
UltraEdit.frInFiles.searchInFilesTypes="*.*"; // Search in all files.
UltraEdit.frInFiles.matchCase=true; // Run a case sensitive search because faster.
UltraEdit.frInFiles.matchWord=false; // Strings not words should be found.
UltraEdit.frInFiles.useOutputWindow=false; // Write found lines to a document window.
UltraEdit.frInFiles.regExp=false; // Run simple, non regular expression finds.
// Advanced Find in Files options:
UltraEdit.frInFiles.displayLinesDoNotMatch=false; // Find lines with string, not opposite.
UltraEdit.frInFiles.useEncoding=false; // Use no special encoding, use system code page.
UltraEdit.frInFiles.ignoreHiddenSubs=false; // Don't ignore hidden directories, search in all subdirectories.
UltraEdit.frInFiles.reverseSearch=false; // We are not interested in files not containing searched string.
UltraEdit.ueReOn();
// Run now the Find in Files with the strings in a loop.
for (var nSearchIndex = 0; nSearchIndex < asSearchStrings.length; nSearchIndex++) {
// Ignore empty lines in list file with the strings to search.
if (!asSearchStrings[nSearchIndex].length) continue;
UltraEdit.frInFiles.find(asSearchStrings[nSearchIndex]);
}
UltraEdit.activeDocument.top(); // Move caret to top of file with the results.
// This last command works only if there was not already the results
// window open on script start as results document window becomes not
// automatically active if already existing on a Find in Files.
}
}
Please note that the script user cannot select the directory. There is no scripting command which opens a
Browse for Directory dialog and returns the full path of the selected directory as string back to the script. The script user must enter the complete directory path or alternatively copy and paste it for example from address bar of Windows Explorer.
The current settings at
Advanced - Configuration - Search - Set Find Output Format define the content of results file after script finished. So you can first configure the output or use some regular expression replaces after the loop to reformat the results file to the output you want.
Topic
Find all lines in active file in all files within a directory contains nearly the same script although I have not used it as template for this script. It looks like similar requirements results really often in similar solutions.