CString strWorkPath;
TCHAR tszWorkPath[MAX_PATH];
GetModuleFileName(NULL, tszWorkPath, MAX_PATH);//获取本地执行的EXE路径
strWorkPath.Format(_T("%s"),tszWorkPath) ;
AfxMessageBox(strWorkPath);
int num = strWorkPath.ReverseFind(_T('//'));
strWorkPath = strWorkPath.Left(num);//剪除exe部分 剩下文件夹路径
AfxMessageBox(strWorkPath);
strWorkPath+=_T("//ping.TXT");
AfxMessageBox(strWorkPath);//要创建的TXT文件的路径和名称
//-------------------
CFile file;
if(file.Open(strWorkPath,CFile::modeReadWrite))//如果路径下的TXT文件已经存在 就读取txt的内容,否则else创建该文件
{
//AfxMessageBox(_T("open success!"));
//定义读写缓冲区
char pbuf[100];
UINT nBytesRead = file.Read( pbuf, 100 );
CString ss;
ss.Format(_T("%s"),pbuf);
//AfxMessageBox(ss);
}
else
{
file.Open(strWorkPath,CFile::modeCreate | CFile::modeReadWrite);//创建txt文件,并写入内容
//AfxMessageBox(_T("not exist to create"));
CString strValue = _T("61.135.169.105a");
int i = strValue.GetLength()*2;
file.Write(strValue,i);
}
CFile::Remove(strWorkPath);//移除txt文件
file.Close(); //文件用完必须关闭,否则下次无法操作