1

如果省略 \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");
}

照原样,它给了我一个错误: Unterminated string constant Line 7 Char 80

4

3 回答 3

3

你必须记得逃避\- 像这样:

"%userprofile%\\My Documents\\"
于 2013-09-12T19:10:54.897 回答
3

在字符串中,\是转义字符。如果你想包含一个\你必须逃避它。

wShell.ExpandEnvironmentStrings("%userprofile%\\My Documents\\");
于 2013-09-12T19:11:34.880 回答
1
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");
}
于 2013-09-12T19:13:46.083 回答