设置当前exe执行文件为进程工作目录

#include <windows.h>#include <iostream>#include <Shlwapi.h>//PathRemoveFileSpec函数头文件#pragma comment(lib, "shlwapi.lib")//VS2013下需加才可以使用PathRemoveFileSpecusing namespace std;int main(){char szCurrentDirectory[MAX_PATH], szExeFilePathFileName[MAX_PATH];//获取当前进程工作目录GetCurrentDirectory(MAX_PATH, szCurrentDirectory);//szCurrentDirectory == 输出 E:\Projects\1cout << "进程当前工作目录为: " << szCurrentDirectory <<endl;//szExeFilePathFileName == exe的路径是 E:\Projects\1\Debug\11.exeGetModuleFileName(NULL, szExeFilePathFileName, MAX_PATH);char drive[MAX_PATH], dir[MAX_PATH], fname[MAX_PATH], ext[MAX_PATH];//szExeFilePathFileName == exe的路径 E:\Projects\1\Debug\11.exe//drive == E: 盘符//dir == \Projects\1\Debug\ 文件中间的路径//fname == 11 不带拓展名的文件名//ext == .exe 文件拓展名//第一种办法获得exe文件目录_splitpath(szExeFilePathFileName, drive, dir, fname, ext);//把盘符和文件中间路径组合起来E:\Projects\1\Debug\ strcat(drive, dir);GetModuleFileName(NULL, szExeFilePathFileName, MAX_PATH);//第二种办法获得exe文件目录//szExeFilePathFileName == E:\Projects\1\Debug\11.exe PathRemoveFileSpec(szExeFilePathFileName);//设置进程工作目录szExeFilePathFileName == E:\Projects\1\DebugSetCurrentDirectory(szExeFilePathFileName);//获得进程工作目录GetCurrentDirectory(MAX_PATH, szCurrentDirectory);//szCurrentDirectory == E:\Projects\1\Debugcout << "调整后, 进程的工作目录为: " << szCurrentDirectory << endl;system("pause");return 0;}

,而不去欣赏今天就开在我们窗口的玫瑰。

设置当前exe执行文件为进程工作目录

相关文章:

你感兴趣的文章:

标签云: