if(file.Open(path_search,CFile::modeCreate|CFile::modeReadWrite|CFile::typeBinary)!=0)
{
CFile file1;
TCHAR *p;
CString filename;
filename=filestruct.name;
p=strchr(filestruct.name,'.');
filename=filename.Mid(0,strlen(filename)-strlen(p));
CString endfilename;
endfilename=dirname+filename;
file.SeekToBegin();
CString strFind = "test.bmp";
CString strReplace = endfilename+".bmp";
CString strFind1 = "test.mid";
CString strReplace1 = endfilename+".mid";
AfxMessageBox(strReplace1);
UINT nFindCount = 8; //strFind的长度
UINT nReplaceCount = 8; //strReplace的长度
char *strBuf = new char[nFindCount + 1];
memset(strBuf , 0 , nFindCount+1);
file1.Open(path1+"file1.tmp",CFile::modeCreate|CFile::modeReadWrite|CFile::typeBinary);//创建临时文件
while(file.Read(strBuf , nFindCount))
{
strBuf[nFindCount] = '\0';
if(!strcmp(strBuf , strFind))
{
memcpy(strBuf,strFind,nFindCount);
}
if(!strcmp(strBuf , strFind1))
{
memcpy(strBuf,strFind1,nFindCount);
}
file1.Write(strBuf,nFindCount);//将数据写回临时文件中
memset(strBuf , 0 , nFindCount+1);
file.Seek(1, CFile::begin);
file1.Seek(1, CFile::begin);
}
if(CopyFile(file1,file,TRUE))//将原文件内容替换成临时文件内容,这儿如何操作啊?
delete []strBuf;
file.Close();
file1.Close();
}
{
CFile file1;
TCHAR *p;
CString filename;
filename=filestruct.name;
p=strchr(filestruct.name,'.');
filename=filename.Mid(0,strlen(filename)-strlen(p));
CString endfilename;
endfilename=dirname+filename;
file.SeekToBegin();
CString strFind = "test.bmp";
CString strReplace = endfilename+".bmp";
CString strFind1 = "test.mid";
CString strReplace1 = endfilename+".mid";
AfxMessageBox(strReplace1);
UINT nFindCount = 8; //strFind的长度
UINT nReplaceCount = 8; //strReplace的长度
char *strBuf = new char[nFindCount + 1];
memset(strBuf , 0 , nFindCount+1);
file1.Open(path1+"file1.tmp",CFile::modeCreate|CFile::modeReadWrite|CFile::typeBinary);//创建临时文件
while(file.Read(strBuf , nFindCount))
{
strBuf[nFindCount] = '\0';
if(!strcmp(strBuf , strFind))
{
memcpy(strBuf,strFind,nFindCount);
}
if(!strcmp(strBuf , strFind1))
{
memcpy(strBuf,strFind1,nFindCount);
}
file1.Write(strBuf,nFindCount);//将数据写回临时文件中
memset(strBuf , 0 , nFindCount+1);
file.Seek(1, CFile::begin);
file1.Seek(1, CFile::begin);
}
if(CopyFile(file1,file,TRUE))//将原文件内容替换成临时文件内容,这儿如何操作啊?
delete []strBuf;
file.Close();
file1.Close();
}
解决方案 »
- winsocket编程,书上解释说:最多支持2个客户连接数
- Xtreme Toolkit在对话框工程里换肤的问题
- 怎么判断VARIANT变量里是空值NULL呢
- 在多文档程序的对话框内如何得到视图指针????
- 鱼翅和熊掌:我该选择哪个?mfc程序设计和vc++技术内幕(第四版)
- 怎么去掉这个警告
- 如何将一个unsigned char* 的值赋给一个unsigned char?
- 在ie中调用activex(ocx),提示应用程序发生异常,未知的软件异常(0xe06d7363),位置为0x77e6a4e1
- 修改器怎么用啊
- 把linux下的2进制数据转到NT下面要做一些什么处理?
- 图象处理中边缘跟踪的算法实现
- 如何在程序中指定一个硬盘上的文件为只读?
{
memcpy(strBuf,strFind,nFindCount);
}
if(!strcmp(strBuf , strFind1))
{
memcpy(strBuf,strFind1,nFindCount);
}
这里是干什么的?如果strBuf==strFind就把strBuf替换为strFind?既然相同还换什么?
要退换文件可一把源文件删掉,把修改后的文件重命名就可以了
name1=path1+"tmp.tmp";
if (!file1.Open(name1,CFile::modeWrite|CFile::modeCreate|CFile::typeBinary, &ex))
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
AfxMessageBox(szError);
}
if(file.Open(path_search,CFile::modeReadWrite|CFile::typeBinary)!=0)
{
TCHAR *p;
CString filename;
filename=filestruct.name;
p=strchr(filestruct.name,'.');
filename=filename.Mid(0,strlen(filename)-strlen(p));
CString endfilename;
endfilename=dirname+filename;
file.SeekToBegin();
CString strFind = "test.bmp";
CString strReplace = endfilename+".bmp";
CString strFind1 = "test.mid";
CString strReplace1 = endfilename+".mid";
UINT nFindCount = 8; //strFind的长度
UINT nReplaceCount = 8; //strReplace的长度
char *strBuf = new char[nFindCount + 1];
memset(strBuf , 0 , nFindCount+1);
while(file.Read(strBuf,nFindCount))
{
strBuf[nFindCount] = '\0';
if(!strcmp(strBuf,strFind))
{
memcpy(strBuf,strReplace,nFindCount+1);
file1.Write(strBuf,strReplace.GetLength());
}
else if(!strcmp(strBuf ,strFind1))
{
UINT filelen1=strReplace1.GetLength();
TRACE("%d",filelen1);
memcpy(strBuf,strReplace1,nFindCount+1);
file1.Write(strBuf,strReplace1.GetLength());
}
else
file1.Write(strBuf,nFindCount+1);
memset(strBuf,0,nFindCount+1);
file.Seek(1,CFile::begin);
file1.Seek(1,CFile::begin); }
delete []strBuf;
DeleteFile(path_search);
file1.Rename(name1,path_search);
file1.Close();
file.Close();