mfc字符串截取-程序路径,文件扩展名等

来源:互联网 发布:时间序列预测 python 编辑:程序博客网 时间:2024/05/23 23:00

//在全路径获取文件名
//const CString & localFileName
wchar_t tempStr[100]; //storage the file name
memset(tempStr,0,100);
int strLen = localFileName.GetLength();
int i = strLen - 1;
int fileLen = 0;
while (localFileName[i] != '//')
{
i--;
}
while(i++ < strLen)
{
tempStr[fileLen++] = localFileName[i];
}


//获取文件扩展名
int i = fileName.GetLength() - 1;
wchar_t fileType[10];
memset(&fileType,0,10);
while(fileName[i] != '.' && i != 0)
{
 i--;
}
if (i == 0)
{
 return NULL;
}
else
{
int j = i + 1;
int k = 0;
while(j < fileName.GetLength())
{
 fileType[k++] = fileName[j++];
}
 CString type = fileType;
}

//更改文件后缀名
 wchar_t strResult[200];
 memset(strResult,0,200);
 int StrLen = zipPath.GetLength();
 for(int i = StrLen; i > 0; i--)
 {
  if (zipPath[i] == '.')
  {
   wcsncpy_s(strResult, zipPath,i);
   break;
  }
 }
 CString iniPath = strResult;
 iniPath.Append(L".ini");