c语言获取可执行文件路径
#include<direct.h>
char path[1024] = {0};
getcwd(path,sizeof(path));
获取exe文件的路径,并且将.exe的文件名替换成新的文件名
1、通过GetModuleFileName
CString filePath;
GetModuleFileName(NULL,filePath.GetBuffer(Max_PATH),MAX_PATH);
filePath.ReleaseBuffer();//获取带.exe文件名的路径
filePath=filePath.Left(filePath.ReverseFind('//')); //注意是单引号
//用双引号会报错(希望有人能解答下)
filePath+=_T("//新的文件名");
CString CProcess::GetExePath()
{
CString filePath;
GetModuleFileName(NULL,filePath.GetBuffer(255),MAX_PATH);
filePath.ReleaseBuffer();//获取带.exe文件名的路径
filePath = filePath.Left(filePath.ReverseFind('//'));
filePath += _T("//");
return filePath;
}
2、
CString filePath;
filePath=theApp.m_pszHelpFilePath;
filePath=filePath.Left(filePath.ReverseFind( '// '));
filePath+= _T("// ");