/ 设置 10 秒超时 // 每日统计清 0 runtime_set('todaycomments', 0); runtime_set('todayarticles', 0); runtime_set('todayusers', 0); if ($forumlist) { $fidarr = array(); foreach ($forumlist as $fid => $forum) { $fidarr[] = $forum['fid']; } forum_update($fidarr, array('todayposts' => 0, 'todaythreads' => 0)); } // 清理临时附件 attach_gc(); // 当天24点 $today = strtotime(date('Ymd')) + 86400; runtime_set('cron_2_last_date', $today, TRUE); // 往前推8个小时,尽量保证在前一天 升级过来和采集的数据会很卡 // table_day_cron($time - 8 * 3600); cache_delete('cron_lock_2'); } } } ?>javascript - How to get %userprofile%My Documents - Stack Overflow|Concepts Of Algorithm

javascript - How to get %userprofile%My Documents - Stack Overflow

admin2025-04-21  3

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
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.

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");
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745201913a290105.html

最新回复(0)