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
("%userprofile%\My Documents\")
?
– j08691
Commented
Sep 12, 2013 at 19:10
In a String, \
is the escape character. If you want to include a \
you have to escape it.
wShell.ExpandEnvironmentStrings("%userprofile%\\My Documents\\");
You must remember to escape the \
- like this:
"%userprofile%\\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");
}