如果省略 \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");
}
照原样,它给了我一个错误:未终止的字符串常量 第 7 行 字符 80
在字符串中, 是转义字符。 如果你想包含一个
你必须转义它。
wShell.ExpandEnvironmentStrings("%userprofile%\My Documents\");
你必须记住转义 - 像这样:
"%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");
}