在C++中设置正在运行的应用程序的当前目录
Setting the current directory of a running app in C++
下面的答案给出了一个使用C#的解决方案,我想知道如果只使用C++(而不是C++\cli),等价物是什么
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
助推中有什么东西可以起作用吗?
基于我一直遇到的这个问题:正确创建并运行带有文件I/O 的win32服务
SetCurrentDirectory
(在Win32中):
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365530%28v=vs.85%29.aspx
boost::filesystem
:中的current_path
http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/reference.html#current_path
BaseDirectory的等效项可能是GetModuleFileName
(第一个参数的句柄为null),然后是GetFullPathName
以从可执行路径获取目录。
使用SetCurrentDirectory WINAPI。
在windows中,_chdir和SetCurrentDirectory之间的区别是什么?
也许也需要模块名称(似乎来自评论),这是我旧商店的一个:-
int main()
{
char path[MAX_PATH]={0};
GetModuleFileName(0,path,MAX_PATH);
}
在Windows中,的完全等价物
System.IO.Directory.SetCurrentDirectory ( System.AppDomain.CurrentDomain.BaseDirectory )`
将是:
// Get full executable path
char buffer[MAX_PATH];
GetModuleFileName(NULL, buffer, MAX_PATH);
// Get executable directory
boost::filesystem::path path(buffer);
path = path.parent_path();
// Set current path to that directory
boost::filesystem::current_path( path );
请注意,没有与平台无关的方法来获取应用程序的目录,因为C++在标准中不认识目录的概念。Boost似乎也没有等效的功能。
相关文章:
- 即使在我为我的应用程序授予管理员后也无法从 Windows 系统复制目录
- 用于检索当前正在使用的应用程序的函数
- 检查任务栏中的当前应用程序吗?(C ,Windows API)
- 在 Ubuntu 16.04 的 usr/local/bin 中安装的 c++ 应用程序在从主目录执行时无法正常运行
- Qt 显示应用程序(如果当前正在运行)
- 在POCO服务器应用程序中预防目录遍历攻击
- 当我想扩展当前应用程序的功能时,出现DIAMOND情况
- 尝试使用VC++编译器构建Qt应用程序:"type_traits":没有这样的文件或目录
- Visual Studio - C++ - 以 32 位或 64 位构建和运行应用程序 - 从适当的程序文件目录加载 D
- 如何启动文件/目录/URL的关联应用程序
- 获取应用程序窗口的完整目录
- 如何使用特定的工作目录运行/调试Netbeans平台应用程序
- 在C++中设置正在运行的应用程序的当前目录
- MacOSX C++带有命令行应用程序的工作目录
- 如何在vc++中执行从安装目录中读取数据的应用程序
- 打开外部应用程序并关闭当前应用程序
- Windows 应用程序在以非管理员身份运行时看到旧版本的文件而不是当前版本
- 当路径中有空格时,从与Qt应用程序相同的目录启动可执行文件
- 如何查找Qt应用程序的安装目录
- 在Qt应用程序中获取当前工作目录