fdh0
2/22/2019 - 9:50 AM

MFC修改文件名 #MFC #name

MFC #MFC #name

CString strOldName= "c:\\1.exe "; 

CString strNewName= "c:\\2.exe "; 

CFile::Rename(strOldName,strNewName);


//============================================
  
CString str = _T("012335678");
str.SetAt( 4, '4' );
此时 str = _T("012345678");


//============================================

CString s=_T("123456");
s.GetAt(0)// 第一个字符 '1'
s.GetAt(1)// 第二个字符 '2'
s.GetAt(2)// 第三个字符 '3'
//以此类推
可以用char获取

if(id_update)
{
	IsFind = find.FindFile(filepath + _T("/*.reg"));	
	CString fullname_reg1,fullname_reg;
	while (IsFind)
	{
		IsFind = find.FindNextFile();
		if (find.IsDots())
		{
			continue;
		}
		else
		{
			filename = find.GetFileName();
			fullname = filepath+ "\\" + filename;
			fullname2 = filepath+ "\\" + filename;
			// [2/19/2019 fdh] 更改区域名中的数字id
			char index_region = filename.GetAt(6);           
			fullname_reg.Format("%s\\%s",strTmp,filename);
			fullname_reg.Replace("\\","\\\\");
			CString fullname_reg1 = fullname_reg;
			filename.SetAt(6,index_region-1);
			fullname_reg1.Format("%s\\%s",strTmp,filename);
			CFile::Rename(fullname_reg,fullname_reg1);
		}	
	}
}
//票面默认参数路径
		
    m_strDefParPath.Format("%s\\DefaultParameter\\AlgLabPrintQI", 
			m_sAlgInitParam.cAlgPath);
		
    m_FileOperate.CreateMultiLevelPath(m_strDefParPath);
typedef struct _ALG_INIT_PARAM
{
	char     cAlgPath[DH_MAX_PATH];        //算法系统配置路径及默认参数路径
	char     cAlglogPath[DH_MAX_PATH];     //算法日志路径
	char     cAlgModePath[DH_MAX_PATH];    //算法模板路径
	UINT     nWidth;                       //图像宽
	UINT     nHeight;                      //图像高
	UINT     nChannels;                    //图像通道数

	// 添加初始化和运算符重载
	_ALG_INIT_PARAM()
	{
		nWidth    = 0;
		nHeight   = 0;
		nChannels = 0;

		memset(&cAlgModePath, 0, DH_MAX_PATH*sizeof(char));
		memset(&cAlgPath, 0, DH_MAX_PATH*sizeof(char));
		memset(&cAlglogPath, 0, DH_MAX_PATH*sizeof(char));
	}
	_ALG_INIT_PARAM(const _ALG_INIT_PARAM& sAIP)
	{
		*this = sAIP;
	}
	_ALG_INIT_PARAM& operator=(const _ALG_INIT_PARAM& sAIParam)
	{
		nWidth    = sAIParam.nWidth;
		nHeight   = sAIParam.nHeight;
		nChannels = sAIParam.nChannels;

		memcpy(&cAlgModePath, sAIParam.cAlgModePath, DH_MAX_PATH*sizeof(char));
		memcpy(&cAlgPath, sAIParam.cAlgPath, DH_MAX_PATH*sizeof(char));
		memcpy(&cAlglogPath, sAIParam.cAlglogPath, DH_MAX_PATH*sizeof(char));
		return (*this);
	}
}s_AlgInitParam;