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
Share Improve this question asked Sep 12, 2013 at 19:06 Cameron DarlingtonCameron Darlington 3652 gold badges7 silver badges14 bronze badges 1-
1
Is the backslash escaping the quote at
("%userprofile%\My Documents\")
? – j08691 Commented Sep 12, 2013 at 19:10
3 Answers
Reset to default 3In 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");
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745201891a4616374.html
评论列表(0条)