获取实际文件夹路径

发布于 2024-07-28 23:26:45 字数 44 浏览 3 评论 0原文

如何在 C++ 中获取程序所在的实际文件夹路径而无需我的 exe 文件名?

How I can get actual folder path where my program is without my exe file name in C++?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜`诱少女 2024-08-04 23:26:45

以下函数将为您提供应用程序路径:

::GetModuleFileName(NULL, szAppPath, MAX_PATH);

现在要提取文件夹,您需要找到最后一个反斜杠:

char szApplicationPath[MAX_PATH] = "";
::GetModuleFileName(NULL, szApplicationPath, MAX_PATH);

//Get the folder part
CString strApplicationFolder;
strApplicationFolder = szApplicationPath;
strApplicationFolder = strApplicationFolder.Left(strApplicationFolder.ReverseFind("\\"));

The following function will give you the application path:

::GetModuleFileName(NULL, szAppPath, MAX_PATH);

Now to extract the folder, you need to find the last backslash:

char szApplicationPath[MAX_PATH] = "";
::GetModuleFileName(NULL, szApplicationPath, MAX_PATH);

//Get the folder part
CString strApplicationFolder;
strApplicationFolder = szApplicationPath;
strApplicationFolder = strApplicationFolder.Left(strApplicationFolder.ReverseFind("\\"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文