找到%LocalAppData%路径并使用JavaScript添加新文件夹
我创建了一个 Windows 7 Gadget,需要在每个用户的计算机上创建一个位置来存储 Settings.ini 文件(从我的 SettingsManager.js 文件创建)。我公司的应用程序打包团队建议我使用
%LOCALAPPDATA%\Microsoft\Windows Sidebar\
,然后添加
Gadgets\iMon.Gadget\
子文件夹。这样每个用户的设置都存储在唯一的位置,并且不会被任何其他应用程序或小工具更改。
我是否需要使用类似的
var fso = new ActiveXObject("Scripting.FileSystemObject");
var folder = fso.CreateFolder("path");
任何有关如何执行此操作的帮助,我们将不胜感激。
更新:我找到了如何获取 %localappdata% 路径,但我仍然需要创建新文件夹。这是我尝试过但没有成功的方法:
var wshshell = new ActiveXObject("wscript.shell");
var localAppData = wshshell.ExpandEnvironmentStrings("%localappdata%");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
I created a Windows 7 Gadget and I need to create a place on each user's computer to store the Settings.ini file (Created from my SettingsManager.js file). The application packaging team at my company recommends I use
%LOCALAPPDATA%\Microsoft\Windows Sidebar\
and then add
Gadgets\iMon.Gadget\
subfolders. This is so each user's settings are stored in a unique location and won't be changed by any other applications or gadgets.
Do I need to use something along the lines of
var fso = new ActiveXObject("Scripting.FileSystemObject");
var folder = fso.CreateFolder("path");
Any help on how to do this would be appreciated.
Update: I found how to get the %localappdata% path, but I still need to create the new folder. Here's what I've tried without success:
var wshshell = new ActiveXObject("wscript.shell");
var localAppData = wshshell.ExpandEnvironmentStrings("%localappdata%");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我明白你想在这里做什么。 iMon.Gadget 是您的小工具的名称吗?如果是这样,则在安装小工具并执行 .gadget 存档时,会自动为您创建此文件夹。小工具的所有文件和文件夹都将解压到
您的代码中,然后您可以继续操作该文件夹(及其子文件夹)中的文件。要获取完整路径,请使用
例如:
I'm not sure I understand what you're trying to do here. is iMon.Gadget the name of your gadget? If so, this folder is automatically created for you upon installation of the gadget when the .gadget archive is executed. All the gadget's files and folders will be unpacked to
In your code, you can then proceed to manipulate files within this folder (and it's subfolders). To get the full path, you use
For example: