Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created December 19, 2011 10:53
Show Gist options
  • Save yoggy/1496617 to your computer and use it in GitHub Desktop.
Save yoggy/1496617 to your computer and use it in GitHub Desktop.
GetModuleFileName() & boost::filesystem sample
std::string get_exe_fullpath()
{
char path[MAX_PATH];
::GetModuleFileName(NULL, path, MAX_PATH);
return std::string(path);
}
std::string get_exe_filename()
{
boost::filesystem::path path(get_exe_fullpath());
std::string tmp = path.filename().string();
return path.filename().string();
}
std::string get_exe_directory()
{
boost::filesystem::path path(get_exe_fullpath());
std::string tmp = path.parent_path().string();
return path.parent_path().string();
}
void change_current_directory_to_exe()
{
std::string path = get_exe_directory();
SetCurrentDirectory(path.c_str());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment