如何获取C中的%AppData%文件夹?
如上,如何使用C获取Windows中的AppData文件夹?
我知道对于 C#,您使用 Environment.SpecialFolder.ApplicationData
As above, how do I get the AppData folder in Windows using C?
I know that for C# you use Environment.SpecialFolder.ApplicationData
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将 SHGetSpecialFolderPath 与 CSIDL 设置为所需的文件夹(可能是 CSIDL_APPDATA 或 CSIDL_LOCAL_APPDATA) 。
您还可以使用较新的 SHGetFolderPath() 和 SHGetKnownFolderPath() 函数。
还有SHGetKnownFolderIDList(),如果您像 COM 一样,有 IKnownFolder::GetPath()。
Use SHGetSpecialFolderPath with a CSIDL set to the desired folder (probably CSIDL_APPDATA or CSIDL_LOCAL_APPDATA).
You can also use the newer SHGetFolderPath() and SHGetKnownFolderPath() functions.
There's also SHGetKnownFolderIDList() and if you like COM there's IKnownFolder::GetPath().
如果我没记错的话应该是
编辑:只需仔细检查,工作正常!
If I recall correctly it should just be
Edit: Just double-checked, works fine!
使用
%APPDATA%
环境变量可能在大多数情况下都有效。但是,如果您想以官方 Windows 方式执行此操作,则应使用SHGetFolderPath
函数,根据您的需要传递 CSIDL 值CSIDL_APPDATA
或CSIDL_LOCAL_APPDATA
。这就是
Environment.GetFolderPath()
方法在 .NET 中使用的方法。编辑: Joey 正确地指出它已被 SHGetKnownFolderPath(在 Windows Vista 中)。对我来说是个好消息:-)。
Using the
%APPDATA%
environment variable will probably work most of the time. However, if you want to do this the official Windows way, you should use use theSHGetFolderPath
function, passing the CSIDL valueCSIDL_APPDATA
orCSIDL_LOCAL_APPDATA
, depending on your needs.This is what the
Environment.GetFolderPath()
method is using in .NET.EDIT: Joey correctly points out that this has been replaced by SHGetKnownFolderPath in Windows Vista. News to me :-).
可以使用这些函数:
您 所以:
You might use these functions:
Like so:
来自 MSDN 的示例代码:
CSIDL_APPDATA = 用户名\应用程序数据。在 Window 10 中为:username\AppData\Roaming
CSIDL_FLAG_CREATE = 与 CSIDL_ 值结合以强制在 SHGetFolderPath() 中创建文件夹
您还可以使用:
CSIDL_LOCAL_APPDATA = username\Local Settings\Application Data(非漫游)
Sample code from MSDN:
CSIDL_APPDATA = username\Application Data. In Window 10 is: username\AppData\Roaming
CSIDL_FLAG_CREATE = combine with CSIDL_ value to force folder creation in SHGetFolderPath()
You can also use:
CSIDL_LOCAL_APPDATA = username\Local Settings\Application Data (non roaming)