跨平台获取当前工作目录
2010-06-01 00:16
281 查看
//Windows c:/ or c:/test/ //Linux / or /user/ /** * @brief getCurrentWorkingPath * * Detailed description. * @return std::string */ inline std::string getCurrentWorkingPath() { #ifdef WIN32 TCHAR workingPath[MAX_PATH]; ZeroMemory(workingPath, MAX_PATH); char path[3000]; memset(path, 0, 3000); if (GetModuleFileName(NULL, workingPath, MAX_PATH) > 0) { unsigned int index; for (unsigned int i = strlen(workingPath); i >= 0 ; --i) { if ((workingPath[i] == '//') || (workingPath[i] == ':')) { index = i; break; } } strncpy(path, workingPath, index + 1); } #else char path[3000]; memset(path, 0, 3000); getcwd(path, 3000); #endif std::string runBatWorkingPath = static_cast<std::string>(path); formatFilePath(runBatWorkingPath); return runBatWorkingPath; }
相关文章推荐
- c++ 设置和获取当前工作目录
- c#获取应用程序目录,C#中得到程序当前工作目录和执行目录方法大全
- 获取当前工作目录
- VC获取当前程序目录[工作目录 VS 程序启动目录]
- Python如何获取、切换当前工作目录?
- C++ 获取当前工作目录的方法
- VC 获取当前工作目录和执行目录的一些方法
- Java虚拟机的一些属性值获取(重点为 当前工作目录)
- java获取当前工作目录
- python获取当前工作目录
- java属性 user.dir获取当前工作目录
- VC获取当前程序目录[工作目录 VS 程序启动目录]
- php获取当前工作目录的方法getcwd
- macos:获取c调用错误原因的描述,,,获取当前的工作目录的方法
- python获取当前工作目录
- 转:VC获取当前程序目录[工作目录 VS 程序启动目录]
- VS获取当前工作默认目录
- Linux中shell脚本获取当前工作目录的方法
- 获取当前目录getcwd,设置工作目录chdir,获取目录信息
- VC 获取当前工作目录和执行目录的一些方法