The following function will work if \My Documents\ is omitted, but I need to get to my documents.
OpenTextFile("test.txt");
function OpenTextFile(file) {
var ObjShell = new ActiveXObject("Shell.Application");
var wShell = new ActiveXObject("WScript.Shell");
var path = wShell.ExpandEnvironmentStrings("%userprofile%\My Documents\");
ObjShell.ShellExecute("Notepad.exe", file, path, "Open", "1");
}
as is, it gives me an error: Unterminated string constant Line 7 Char 80
The following function will work if \My Documents\ is omitted, but I need to get to my documents.
OpenTextFile("test.txt");
function OpenTextFile(file) {
var ObjShell = new ActiveXObject("Shell.Application");
var wShell = new ActiveXObject("WScript.Shell");
var path = wShell.ExpandEnvironmentStrings("%userprofile%\My Documents\");
ObjShell.ShellExecute("Notepad.exe", file, path, "Open", "1");
}
as is, it gives me an error: Unterminated string constant Line 7 Char 80
javascript
Share
Improve this question
asked Sep 12, 2013 at 19:06
Cameron DarlingtonCameron Darlington36522 gold badges77 silver badges1414 bronze badges1
1Is the backslash escaping the quote at ("%userprofile%\My Documents\")?
– j08691
CommentedSep 12, 2013 at 19:10
Add a ment
|
3 Answers
3
Reset to default
3
In a String, \ is the escape character. If you want to include a \ you have to escape it.
OpenTextFile("test.txt");
function OpenTextFile(file) {
var ObjShell = new ActiveXObject("Shell.Application");
var wShell = new ActiveXObject("WScript.Shell");
var path = wShell.ExpandEnvironmentStrings("%userprofile%\\My Documents\\");
ObjShell.ShellExecute("Notepad.exe", file, path, "Open", "1");
}