Created
December 19, 2011 10:53
-
-
Save yoggy/1496617 to your computer and use it in GitHub Desktop.
GetModuleFileName() & boost::filesystem sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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