如何用C ++打开%appdata%文件夹? [英] How to open a folder in %appdata% with C++?

查看:604
本文介绍了如何用C ++打开%appdata%文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,appdata文件夹是

As you all know, the appdata folder is this

 C:\Users\*Username*\AppData\Roaming

在Windows 7上

on windows 7

由于我的应用程序将部署在各种Windows操作系统上,我需要能够获得文件夹100%的时间。
问题是你如何在C ++中做到这一点?因为我不知道确切的Windows操作系统,它可以是XP,Vista或7,最重要的是我不知道用户名是什么。

Since my application will be deployed on all kinds of Windows OSes i need to be able to get the folder 100% percent of the time. The question is how do you do it in C++? Since i don't know the the exact Windows OS it could be XP,Vista or 7 and most importantly i don't know what the Username is.

推荐答案

为了与所有版本的Windows最大兼容,您可以使用 SHGetFolderPath 函数

它要求您指定 CSIDL 值,以获取要检索其路径的文件夹。对于应用程序数据文件夹,这将是 CSIDL_APPDATA

For maximum compatibility with all versions of Windows, you can use the SHGetFolderPath function.
It requires that you specify the CSIDL value for the folder whose path you want to retrieve. For the application data folder, that would be CSIDL_APPDATA.

在Windows Vista及更高版本中,您应该使用 SHGetKnownFolderPath 函数,这要求您指定文件夹的 KNOWNFOLDERID 值。同样,对于应用程序数据文件夹,适当的值为 FOLDERID_RoamingAppData

On Windows Vista and later, you should use the SHGetKnownFolderPath function instead, which requires that you specify the folder's KNOWNFOLDERID value. Again, for the application data folder, the appropriate value is FOLDERID_RoamingAppData.

要使用这些函数C ++应用程序,您需要包括 shlobj.h

To use either of these functions from your C++ application, you'll need to include shlobj.h.

这篇关于如何用C ++打开%appdata%文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆