GetListOfFiles.js produces always a list of existing files. But to answer your question, no there is no command to check if a file exist or not.
It is also not possible to simply open a file and then check if the active file has the name used in the open command. If you try from within a script to open a not existing file you will get an error message and the script halts until you close the error message.
You can check file existence with a batch file, for example see
checking if files exist.
But I have had an idea how to check file existence from within an UltraEdit script. Use the function below:
- Code: Select all
function FileExist (sFileName) {
// Is the required parameter passed to the function?
if (typeof(sFileName) != "string") return false;
// Is the file name an empty string?
if (sFileName == "") return false;
// Store the index of the active clipboard.
var nActiveClipboard = UltraEdit.clipboardIdx;
// Use clipboard 9 to save current output window data, but
// before save content of clipboard 9 into string variable.
UltraEdit.selectClipboard(9);
var sClipboard9 = UltraEdit.clipboardContent;
UltraEdit.outputWindow.copy();
UltraEdit.outputWindow.clear();
// Run Find in Files with an empty search string and with the passed file
// name as file type. The search result is written to the output window.
UltraEdit.frInFiles.regExp=false;
UltraEdit.frInFiles.matchCase=true;
UltraEdit.frInFiles.matchWord=false;
UltraEdit.frInFiles.searchSubs=false;
UltraEdit.frInFiles.unicodeSearch=false;
UltraEdit.frInFiles.filesToSearch=0;
UltraEdit.frInFiles.directoryStart="";
UltraEdit.frInFiles.useOutputWindow=true;
UltraEdit.frInFiles.ignoreHiddenSubs=false;
UltraEdit.frInFiles.displayLinesDoNotMatch=false;
UltraEdit.frInFiles.searchInFilesTypes=sFileName;
UltraEdit.frInFiles.find("");
// Use clipboard 8 to get search result in output window, but
// before save content of clipboard 8 into string variable.
UltraEdit.selectClipboard(8);
var sClipboard8 = UltraEdit.clipboardContent;
UltraEdit.outputWindow.copy();
// Search for the passed file name in the search result.
// If not found, i.e. returned index == -1, the file does not exist.
var bFileFound = (UltraEdit.clipboardContent.indexOf(sFileName) < 0) ? false : true;
// Restore content of clipboard 8.
UltraEdit.clearClipboard();
if (sClipboard8 != "") UltraEdit.clipboardContent = sClipboard8;
// Restore content of the output window.
UltraEdit.selectClipboard(9);
UltraEdit.outputWindow.clear();
UltraEdit.outputWindow.write(UltraEdit.clipboardContent);
// Restore content of clipboard 9.
UltraEdit.clearClipboard();
if (sClipboard9 != "") UltraEdit.clipboardContent = sClipboard9;
// Select the previous active clipboard.
UltraEdit.selectClipboard(nActiveClipboard);
// Return the result of the file existence check.
return bFileFound;
}