16,467
社区成员
发帖
与我相关
我的任务
分享
CStdioFile newfile;
CStdioFile oldfile;//这仨我在.h文件中声明的
CString A;
void CMFCApplication1Dlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
TCHAR szFilter[] = _T("DAT Files (*.dat)|*.dat|All Files (*.*)|*.*||");//|所有文件(*.*)|*.*||
CFileDialog fileopen(TRUE, _T("bat"), NULL, 0, szFilter, this);
CString oldFilePath;
CString newFilePath;
CString fileext;
CString filetitle;
if (fileopen.DoModal() == IDOK)
{
oldFilePath = fileopen.GetPathName();
SetDlgItemText(IDC_EDIT1, oldFilePath);//设置对话框中的路径
while (oldFilePath)
{
int dirpos = oldFilePath.ReverseFind('.');
fileext = oldFilePath.Right(oldFilePath.GetLength() - dirpos - 1);
dirpos = oldFilePath.ReverseFind('\\');
CString filedir1 = oldFilePath.Left(dirpos + 1) + "bin\\";
BOOL m_b = CreateDirectory(filedir1, NULL);
CString fname = oldFilePath.Right(oldFilePath.GetLength() - dirpos - 1);
dirpos = fname.ReverseFind('.');
filetitle = fname.Left(dirpos);
newFilePath = filedir1 + filetitle + ".txt";
if (oldfile.Open(oldFilePath, CFile::modeRead) == NULL)
{
AfxMessageBox("文件打开失败");
return;
}
Analysis();
CFileException fileException;
if (newfile.Open(newFilePath, CFile::modeCreate | CFile::modeWrite | CFile::typeText), &fileException)
{
WriteFile();
}
else
{
TRACE("Can't open file %s,error=%u/n", newFilePath, fileException.m_cause);
}
newfile.Flush();
oldfile.Close();
newfile.Close();
break;
}
}
}
void CMFCApplication1Dlg::WriteFile()
{
CString str;
int n;
str.Format("%s\n", "#Password");
newfile.WriteString(str);
str.Format("\t%d\t", ner.num);
newfile.WriteString(str);
n = GetLastError();
}