在WPS JSA中,获取系统桌面路径的方法有哪些?
实测几个,只有固定路径能用
function getDataFolder() {
try {
// 方法1: 使用WPS JSA环境变量
const desktopPath = Application.Path + "\\Desktop\\";
if (Dir(desktopPath + "日常数据\\", 16) !== "") {
return desktopPath + "日常数据\\";
}
// 方法2: 使用Windows脚本宿主对象
const shell = new ActiveXObject("WScript.Shell");
const wshDesktop = shell.SpecialFolders("Desktop");
if (Dir(wshDesktop + "\\日常数据\\", 16) !== "") {
return wshDesktop + "\\日常数据\\";
}
// 方法3: 使用环境变量
const userProfile = Environ("USERPROFILE");
if (userProfile && Dir(userProfile + "\\Desktop\\日常数据\\", 16) !== "") {
return userProfile + "\\Desktop\\日常数据\\";
}
// 方法4: 默认路径
return "C:\\Users\\" + Environ("USERNAME") + "\\Desktop\\日常数据\\";
} catch (e) {
// 最终回退方案
return "C:\\Users\\xin\\Desktop\\日常数据\\";
}
}
创作者俱乐部成员