Hallo all
I made two scripts using the GetFilePath function, one to insert a header with filepath. I got the insert to run correctly but for the update the backslashes are not written.
For comparison here the lines, the first one for the insert and the second one for the update.
I did not find an answer where I made the error or how to escape the backslashes.
InsertHeader.js:
UpdateHeader.js
I made two scripts using the GetFilePath function, one to insert a header with filepath. I got the insert to run correctly but for the update the backslashes are not written.
For comparison here the lines, the first one for the insert and the second one for the update.
Code: Select all
//Insert Filepath
UltraEdit.activeDocument.write("-- = $Id: " + GetFilePath() + GetNameOfFile() + "\ $\r\n");
//UpdateFilepath
UltraEdit.activeDocument.findReplace.replace("\\\$Id: .* \\\$","$Id: " + GetFilePath() + GetNameOfFile() + "\ $");
InsertHeader.js:
Code: Select all
//Insert Header Script
var nCursorPos = UltraEdit.activeDocument.currentPos;
UltraEdit.activeDocument.copyFilePath();
UltraEdit.activeDocument.write("-- =======================================================================\r\n");
UltraEdit.activeDocument.write("-- = $Project: OTMS $\r\n");
UltraEdit.activeDocument.write("-- = $Description: Descriptiontext $\r\n");
//Insert Author
UltraEdit.activeDocument.write("-- = $Author: USERNAME $\r\n");
//Insert Date
function todaysdate() {
var currentDate = new Date();
currentDate.setDate(currentDate.getDate());
var d = currentDate.getDay()
var dt = currentDate.getDate();
dt = (dt < 10 ? '0' : '') + dt;
var m = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
var mn = currentDate.getMinutes();
mn = (mn < 10 ? '0' : '') + mn;
var hr = currentDate.getHours();
hr = (hr < 10 ? '0' : '') + hr;
UltraEdit.activeDocument.write("-- = $Date: " + year + "/" + m + "/" + dt + "/" + hr + ":" + mn + " $\r\n")}
todaysdate();
//Insert Id
function GetFileExt (CompleteFileNameOrDocIndexNumber, bWithPoint)
{
var sFileExtension = "";
var sNameOfFile = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (sFileExtension.length && (typeof(bWithPoint) == "boolean"))
{
if (bWithPoint) sFileExtension = "." + sFileExtension;
}
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
if (!sFullFileName.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is an empty string!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: The input string is an empty string!");
}
return sFileExtension;
}
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0) sNameOfFile = sFullFileName;
else
{
if (nLastDirDelim == (sFullFileName.length-1))
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is a path string!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: The input string is a path string!");
}
return sFileExtension;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: No document is open currently!");
}
return sFileExtension;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: A document with index number "+nDocumentNumber+" does not exist!");
}
return sFileExtension;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File extension can't be determined from a new file!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: File extension can't be determined from a new file!");
}
return sFileExtension;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
}
var nLastPointPos = sNameOfFile.lastIndexOf(".");
if ((nLastPointPos < 1) || (nLastPointPos == (sNameOfFile.length-1)))
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File \""+sNameOfFile+"\" has no file extension!","GetFileExt Warning");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: File \""+sNameOfFile+"\" has no file extension!");
}
if (typeof(bWithPoint) == "boolean")
{
if (bWithPoint) return ".";
}
return "";
}
if (typeof(bWithPoint) != "boolean") nLastPointPos++;
else if (!bWithPoint) nLastPointPos++;
sFileExtension = sNameOfFile.substring(nLastPointPos);
return sFileExtension;
}
function GetFileName (CompleteFileNameOrDocIndexNumber, bWithPoint, bWithPath)
{
var sNameOfFile = "";
var sFilePath = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (sNameOfFile.length)
{
if (typeof(bWithPoint) == "boolean")
{
if (bWithPoint) sNameOfFile += '.';
}
if (sFilePath.length && (typeof(bWithPath) == "boolean"))
{
if (bWithPath) sNameOfFile = sFilePath + sNameOfFile;
}
}
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
if (!sFullFileName.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is an empty string!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: The input string is an empty string!");
}
return sNameOfFile;
}
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0) sNameOfFile = sFullFileName;
else
{
if (nLastDirDelim == (sFullFileName.length-1))
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is a path string!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: The input string is a path string!");
}
return sNameOfFile;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
sFilePath = sFullFileName.substring(0,nLastDirDelim);
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: No document is open currently!");
}
return sNameOfFile;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: A document with index number "+nDocumentNumber+" does not exist!");
}
return sNameOfFile;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File name can't be determined from a new file!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: File name can't be determined from a new file!");
}
return sNameOfFile;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
sFilePath = sFullFileName.substring(0,nLastDirDelim);
}
var nLastPointPos = sNameOfFile.lastIndexOf(".");
if (nLastPointPos <= 0)
{
if (!nLastPointPos)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File \""+sNameOfFile+"\" starts with a dot!","GetFileName Warning");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: File \""+sNameOfFile+"\" starts with a dot!");
}
}
if (typeof(bWithPoint) == "boolean")
{
if (bWithPoint) sNameOfFile += '.';
}
if (typeof(bWithPath) != "boolean") return sNameOfFile;
if (!bWithPath) return sNameOfFile;
return sFilePath + sNameOfFile;
}
if (typeof(bWithPoint) == "boolean")
{
if (bWithPoint) nLastPointPos++;
}
sFullFileName = sNameOfFile.substring(0,nLastPointPos);
if (typeof(bWithPath) != "boolean") return sFullFileName;
if (!bWithPath) return sFullFileName;
return sFilePath + sFullFileName;
}
function GetFilePath (CompleteFileNameOrDocIndexNumber)
{
var sFilePath = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File path can't be determined from \""+sFullFileName+"\"!","GetFilePath Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFilePath: File path can't be determined from \""+sFullFileName+"\"!");
}
return sFilePath;
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetFilePath Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFilePath: No document is open currently!");
}
return sFilePath;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetFilePath Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFilePath: A document with index number "+nDocumentNumber+" does not exist!");
}
return sFilePath;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File path can't be determined from a new file!","GetFilePath Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFilePath: File path can't be determined from a new file!");
}
return sFilePath;
}
}
if (sFullFileName.charAt(nLastDirDelim) != '|')
{
nLastDirDelim++;
sFilePath = sFullFileName.substring(0,nLastDirDelim);
}
else
{
sFilePath = sFullFileName.substring(0,nLastDirDelim) + "/";
}
return sFilePath;
}
function GetFolderName (CompleteFileNameOrDocIndexNumber)
{
var sFolderName = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("Folder name can't be determined from \""+sFullFileName+"\"!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: Folder name can't be determined from \""+sFullFileName+"\"!");
}
return sFolderName;
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: No document is open currently!");
}
return sFolderName;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: A document with index number "+nDocumentNumber+" does not exist!");
}
return sFolderName;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("Folder name can't be determined from a new file!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: Folder name can't be determined from a new file!");
}
return sFolderName;
}
}
if (!nLastDirDelim)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The file is stored in root of a drive!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The file is stored in root of a drive!");
}
return sFolderName;
}
var sFilePath = sFullFileName.substring(0,nLastDirDelim);
if (!sFilePath.search(/^[A-Za-z]:$/))
{
var sDriveLetter = sFilePath.charAt(0).toUpperCase();
if (nOutputType == 2)
{
UltraEdit.messageBox("The file is stored in root of drive "+sDriveLetter+":","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The file is stored in root of drive "+sDriveLetter+":");
}
return sFolderName;
}
if (!sFilePath.search(/^[\/\\]{2}.+?[\/\\][^\\]+$/))
{
sFilePath += sFullFileName.charAt(nLastDirDelim);
if (nOutputType == 2)
{
UltraEdit.messageBox("The file is stored in shared folder \""+sFilePath+"\"!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The file is stored in shared folder \""+sFilePath+"\"!");
}
return sFolderName;
}
if (!sFilePath.search(/^(?:s?ftp:\/\/|S?FTP::)[^\/\\]+[\/\\]*$/))
{
var sServerName = sFilePath.replace(/^(?:s?ftp:\/\/|S?FTP::)([^\/\\]+)[\/\\]*$/,"$1");
if (nOutputType == 2)
{
UltraEdit.messageBox("The file is stored in root of FTP server \""+sServerName+"\"!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The file is stored in root of FTP server \""+sServerName+"\"!");
}
return sFolderName;
}
var nDirDelim = sFilePath.lastIndexOf("/");
if (nDirDelim < 0)
{
nDirDelim = sFilePath.lastIndexOf("\\");
}
nDirDelim++;
var sLastFolderName = sFilePath.substring(nDirDelim);
if (!sLastFolderName.search(/^[.\/\\]+$/))
{
sFilePath += sFullFileName.charAt(nLastDirDelim);
if (nOutputType == 2)
{
UltraEdit.messageBox("The folder name can't be determined from relative file path \""+sFilePath+"\"!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The folder name can't be determined from relative file path \""+sFilePath+"\"!");
}
return sFolderName;
}
return sLastFolderName;
}
function GetNameOfFile (CompleteFileNameOrDocIndexNumber)
{
var sNameOfFile = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
if (!sFullFileName.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is an empty string!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: The input string is an empty string!");
}
return sNameOfFile;
}
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0) sNameOfFile = sFullFileName;
else
{
if (nLastDirDelim == (sFullFileName.length-1))
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is a path string!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: The input string is a path string!");
}
return sNameOfFile;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: No document is open currently!");
}
return sNameOfFile;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: A document with index number "+nDocumentNumber+" does not exist!");
}
return sNameOfFile;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File name can't be determined from a new file!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: File name can't be determined from a new file!");
}
return sNameOfFile;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
}
return sNameOfFile;
}
var g_nDebugMessage = 2;
var sDemoName = "";
UltraEdit.activeDocument.write("-- = $Id: " + GetFilePath() + GetNameOfFile() + "\ $\r\n");
UltraEdit.activeDocument.write("-- =======================================================================\r\n");
UltraEdit.clearClipboard();
UltraEdit.activeDocument.gotoPos(nCursorPos);
UltraEdit.outputWindow.showOutput = true;
UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("Unsaved Changes, please save before running script.");
Code: Select all
//Update Header Script
var nCursorPos = UltraEdit.activeDocument.currentPos;
UltraEdit.activeDocument.copyFilePath();
UltraEdit.perlReOn();
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.replaceAll=true;
UltraEdit.activeDocument.findReplace.regExp = true;
//Update Author
UltraEdit.activeDocument.findReplace.replace("\\\$Author: .* \\\$","$Author: USERNAME $");
//Update Date
function todaysdate() {
var currentDate = new Date();
currentDate.setDate(currentDate.getDate());
var d = currentDate.getDay()
var dt = currentDate.getDate();
dt = (dt < 10 ? '0' : '') + dt;
var m = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
var mn = currentDate.getMinutes();
mn = (mn < 10 ? '0' : '') + mn;
var hr = currentDate.getHours();
hr = (hr < 10 ? '0' : '') + hr;
UltraEdit.activeDocument.findReplace.replace("\\\$Date: .* \\\$","$Date: " + year + "/" + m + "/" + dt + "/" + hr + ":" + mn + " $")}
todaysdate();
//Update Id
function GetFileExt (CompleteFileNameOrDocIndexNumber, bWithPoint)
{
var sFileExtension = "";
var sNameOfFile = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (sFileExtension.length && (typeof(bWithPoint) == "boolean"))
{
if (bWithPoint) sFileExtension = "." + sFileExtension;
}
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
if (!sFullFileName.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is an empty string!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: The input string is an empty string!");
}
return sFileExtension;
}
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0) sNameOfFile = sFullFileName;
else
{
if (nLastDirDelim == (sFullFileName.length-1))
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is a path string!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: The input string is a path string!");
}
return sFileExtension;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: No document is open currently!");
}
return sFileExtension;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: A document with index number "+nDocumentNumber+" does not exist!");
}
return sFileExtension;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File extension can't be determined from a new file!","GetFileExt Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: File extension can't be determined from a new file!");
}
return sFileExtension;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
}
var nLastPointPos = sNameOfFile.lastIndexOf(".");
if ((nLastPointPos < 1) || (nLastPointPos == (sNameOfFile.length-1)))
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File \""+sNameOfFile+"\" has no file extension!","GetFileExt Warning");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileExt: File \""+sNameOfFile+"\" has no file extension!");
}
if (typeof(bWithPoint) == "boolean")
{
if (bWithPoint) return ".";
}
return "";
}
if (typeof(bWithPoint) != "boolean") nLastPointPos++;
else if (!bWithPoint) nLastPointPos++;
sFileExtension = sNameOfFile.substring(nLastPointPos);
return sFileExtension;
}
function GetFileName (CompleteFileNameOrDocIndexNumber, bWithPoint, bWithPath)
{
var sNameOfFile = "";
var sFilePath = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (sNameOfFile.length)
{
if (typeof(bWithPoint) == "boolean")
{
if (bWithPoint) sNameOfFile += '.';
}
if (sFilePath.length && (typeof(bWithPath) == "boolean"))
{
if (bWithPath) sNameOfFile = sFilePath + sNameOfFile;
}
}
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
if (!sFullFileName.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is an empty string!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: The input string is an empty string!");
}
return sNameOfFile;
}
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0) sNameOfFile = sFullFileName;
else
{
if (nLastDirDelim == (sFullFileName.length-1))
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is a path string!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: The input string is a path string!");
}
return sNameOfFile;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
sFilePath = sFullFileName.substring(0,nLastDirDelim);
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: No document is open currently!");
}
return sNameOfFile;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: A document with index number "+nDocumentNumber+" does not exist!");
}
return sNameOfFile;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File name can't be determined from a new file!","GetFileName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: File name can't be determined from a new file!");
}
return sNameOfFile;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
sFilePath = sFullFileName.substring(0,nLastDirDelim);
}
var nLastPointPos = sNameOfFile.lastIndexOf(".");
if (nLastPointPos <= 0)
{
if (!nLastPointPos)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File \""+sNameOfFile+"\" starts with a dot!","GetFileName Warning");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFileName: File \""+sNameOfFile+"\" starts with a dot!");
}
}
if (typeof(bWithPoint) == "boolean")
{
if (bWithPoint) sNameOfFile += '.';
}
if (typeof(bWithPath) != "boolean") return sNameOfFile;
if (!bWithPath) return sNameOfFile;
return sFilePath + sNameOfFile;
}
if (typeof(bWithPoint) == "boolean")
{
if (bWithPoint) nLastPointPos++;
}
sFullFileName = sNameOfFile.substring(0,nLastPointPos);
if (typeof(bWithPath) != "boolean") return sFullFileName;
if (!bWithPath) return sFullFileName;
return sFilePath + sFullFileName;
}
function GetFilePath (CompleteFileNameOrDocIndexNumber)
{
var sFilePath = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File path can't be determined from \""+sFullFileName+"\"!","GetFilePath Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFilePath: File path can't be determined from \""+sFullFileName+"\"!");
}
return sFilePath;
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetFilePath Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFilePath: No document is open currently!");
}
return sFilePath;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetFilePath Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFilePath: A document with index number "+nDocumentNumber+" does not exist!");
}
return sFilePath;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File path can't be determined from a new file!","GetFilePath Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFilePath: File path can't be determined from a new file!");
}
return sFilePath;
}
}
if (sFullFileName.charAt(nLastDirDelim) != '|')
{
nLastDirDelim++;
sFilePath = sFullFileName.substring(0,nLastDirDelim);
}
else
{
sFilePath = sFullFileName.substring(0,nLastDirDelim) + "/";
}
return sFilePath;
}
function GetFolderName (CompleteFileNameOrDocIndexNumber)
{
var sFolderName = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("Folder name can't be determined from \""+sFullFileName+"\"!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: Folder name can't be determined from \""+sFullFileName+"\"!");
}
return sFolderName;
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: No document is open currently!");
}
return sFolderName;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: A document with index number "+nDocumentNumber+" does not exist!");
}
return sFolderName;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("Folder name can't be determined from a new file!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: Folder name can't be determined from a new file!");
}
return sFolderName;
}
}
if (!nLastDirDelim)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The file is stored in root of a drive!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The file is stored in root of a drive!");
}
return sFolderName;
}
var sFilePath = sFullFileName.substring(0,nLastDirDelim);
if (!sFilePath.search(/^[A-Za-z]:$/))
{
var sDriveLetter = sFilePath.charAt(0).toUpperCase();
if (nOutputType == 2)
{
UltraEdit.messageBox("The file is stored in root of drive "+sDriveLetter+":","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The file is stored in root of drive "+sDriveLetter+":");
}
return sFolderName;
}
if (!sFilePath.search(/^[\/\\]{2}.+?[\/\\][^\\]+$/))
{
sFilePath += sFullFileName.charAt(nLastDirDelim);
if (nOutputType == 2)
{
UltraEdit.messageBox("The file is stored in shared folder \""+sFilePath+"\"!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The file is stored in shared folder \""+sFilePath+"\"!");
}
return sFolderName;
}
if (!sFilePath.search(/^(?:s?ftp:\/\/|S?FTP::)[^\/\\]+[\/\\]*$/))
{
var sServerName = sFilePath.replace(/^(?:s?ftp:\/\/|S?FTP::)([^\/\\]+)[\/\\]*$/,"$1");
if (nOutputType == 2)
{
UltraEdit.messageBox("The file is stored in root of FTP server \""+sServerName+"\"!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The file is stored in root of FTP server \""+sServerName+"\"!");
}
return sFolderName;
}
var nDirDelim = sFilePath.lastIndexOf("/");
if (nDirDelim < 0)
{
nDirDelim = sFilePath.lastIndexOf("\\");
}
nDirDelim++;
var sLastFolderName = sFilePath.substring(nDirDelim);
if (!sLastFolderName.search(/^[.\/\\]+$/))
{
sFilePath += sFullFileName.charAt(nLastDirDelim);
if (nOutputType == 2)
{
UltraEdit.messageBox("The folder name can't be determined from relative file path \""+sFilePath+"\"!","GetFolderName Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetFolderName: The folder name can't be determined from relative file path \""+sFilePath+"\"!");
}
return sFolderName;
}
return sLastFolderName;
}
function GetNameOfFile (CompleteFileNameOrDocIndexNumber)
{
var sNameOfFile = "";
var sFullFileName = "";
var nLastDirDelim = -1;
var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
{
sFullFileName = CompleteFileNameOrDocIndexNumber;
if (!sFullFileName.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is an empty string!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: The input string is an empty string!");
}
return sNameOfFile;
}
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0) sNameOfFile = sFullFileName;
else
{
if (nLastDirDelim == (sFullFileName.length-1))
{
if (nOutputType == 2)
{
UltraEdit.messageBox("The input string is a path string!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: The input string is a path string!");
}
return sNameOfFile;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
}
}
else
{
if (UltraEdit.document.length < 1)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("No document is open currently!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: No document is open currently!");
}
return sNameOfFile;
}
var nDocumentNumber = -1;
if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
{
nDocumentNumber = CompleteFileNameOrDocIndexNumber;
}
if (nDocumentNumber >= UltraEdit.document.length)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: A document with index number "+nDocumentNumber+" does not exist!");
}
return sNameOfFile;
}
if (nDocumentNumber < 0)
{
sFullFileName = UltraEdit.activeDocument.path;
if (UltraEdit.activeDocument.isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
else
{
sFullFileName = UltraEdit.document[nDocumentNumber].path;
if (UltraEdit.document[nDocumentNumber].isFTP())
{
nLastDirDelim = sFullFileName.lastIndexOf("|");
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
}
}
if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
if (nLastDirDelim < 0)
{
if (nOutputType == 2)
{
UltraEdit.messageBox("File name can't be determined from a new file!","GetNameOfFile Error");
}
else if (nOutputType == 1)
{
if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetNameOfFile: File name can't be determined from a new file!");
}
return sNameOfFile;
}
nLastDirDelim++;
sNameOfFile = sFullFileName.substring(nLastDirDelim);
}
return sNameOfFile;
}
var g_nDebugMessage = 2;
var sDemoName = "";
UltraEdit.activeDocument.findReplace.replace("\\\$Id: .* \\\$","$Id: " + GetFilePath() + GetNameOfFile() + "\ $");
UltraEdit.clearClipboard();
UltraEdit.activeDocument.gotoPos(nCursorPos);