There is a misunderstanding. The help is right.
The parameter of command
UltraEdit.open() and the first parameter of
UltraEdit.closeFile() must be a string value. So here comes a Javascript for beginners lesson.
A string is defined in Javascript with:
- text enclosed in straight double quotes " - a straight single quote character ' within the text must not be escaped with a backslash, or
- text enclosed in straight single quotes ' - a straight double quote character " within the text must not be escaped with a backslash.
The backslash
\ has a special meaning in Javascript strings. It is the escape character for special characters like
\t for a horizontal tab,
\r for a carriage return,
\n for a line-feed, ... It is necessary to write 2 backslashes
\\ to inform the Javascript interpreter that the string should contain the backslash character itself.
Some examples:
For opening file
C:\temp\test.txt:
UltraEdit.open("C:
\\temp
\\test.txt
");For opening file
C:\temp\test'1.txt:
UltraEdit.open("C:
\\temp
\\test
'1.txt
");Single quote characters are allowed in file names on Windows file systems.
For opening file
C:\temp\test'1.txt:
UltraEdit.open('C:
\\temp
\\test
\'1.txt
');If single quote characters are used to define the string value, a single quote character inside the string value must be escaped with a backslash.
A file name cannot contain a straight double quote character. So there is no reason to use single quotes to define the file name string value without the need to escape a straight double quote character. Such a string value definition with single quotes makes sense for example in a search or replace string like
UltraEdit.activeDocument.findReplace.replace('<a href=
"www.ultraedit.com
"',
'<a href=
"www.idmcomp.com
"');The same command with using straight double quotes for string value definition is:
UltraEdit.activeDocument.findReplace.replace("<a href=
\"www.ultraedit.com
\"",
"<a href=
\"www.idmcomp.com
\"");Now we take a look on some wrongly defined file name string values.
For opening file
C:\temp\test.txt:
UltraEdit.open("C:
\temp
\test.txt
");That command produces an error message because the Javascript interpreter passed to command
UltraEdit.open() the string
C:tabemptabest.txt and such a file does surely not exist.
For opening file
C:\temp\test.txt:
UltraEdit.open(C:
\\temp
\\test.txt
); or
UltraEdit.open(C:\temp\test.txt
);Both commands results in syntax error message on script start reported by Javascript interpreter captured by UltraEdit and written to output window. The 2 strings are not valid strings as not enclosed in double or single quotes, but are at same time also invalid names for a variable.
Instead of passing a fixed string value defined directly in the file opening or closing command, it is of course also possible to call the commands with a variable already holding the file name.
UltraEdit.activeDocument.path is such a string variable.
path is member variable (property) of type string of class (object)
activeDocument which is again a member variable of class
UltraEdit.
So you can use also
var sFileName = "C:
\\temp
\\test.txt
";
UltraEdit.open(sFileName);Or if there is currently a file name selected in active file
UltraEdit.open(UltraEdit.activeDocument.selection);