//文件路径浏览对话框参考:http://blog.csdn.net/liuwumiyuhuiping/article/details/7348591
void CMainFrame::OnFileCopySave()
{
// TODO: Add your command handler code here
CString pzFullPath;
CString pzNewBasePath;
CString pzNewProjName;
//AfxMessageBox("项目另存为");
CString filter;
filter="电气数据(*.grid)|*.grid||";
CFileDialog dlg(FALSE,_T("grid"),_T("项目备份"),OFN_HIDEREADONLY,filter);
if(dlg.DoModal()==IDOK)
{
pzFullPath=dlg.GetPathName();
//MessageBox(pzFullPath);
pzNewProjName = pzFullPath.Right(pzFullPath.GetLength()-1-pzFullPath.ReverseFind('\\'));
pzNewProjName = pzNewProjName.Left(pzNewProjName.ReverseFind('.'));
//MessageBox(pzNewProjName);
pzNewBasePath = pzFullPath.Left(pzFullPath.ReverseFind('\\'))+"\\"+pzNewProjName;
//MessageBox(pzNewBasePath);
//创建目录
if (!PathFileExists(pzNewBasePath))
{
if (!CreateDirectory(pzNewBasePath,_T("")))
{
AfxMessageBox(_T("创建目录:") + pzNewBasePath + _T("失败"));
return;
}else{
//AfxMessageBox("已创建目录"+ pzNewBasePath);
}
}else{
AfxMessageBox("目录已存在");
}
/*将: projectBasePath/projectTitle.grid & projectBasePath/projectTitle.mdb 拷贝到目录 pzNewBasePath 下
projectBasePath = strPathName.Left(strPathName.ReverseFind(_T('\\')));
strFileName = strPathName.Right(strPathName.GetLength()-1-strPathName.ReverseFind('\\'));
projectTitle = strFileName.Left(strFileName.ReverseFind(_T('.')));
*/
CString sourceFile,distFile;
sourceFile = projectBasePath + _T("\\") + projectTitle + _T(".mdb");
distFile = pzNewBasePath + _T("\\") + pzNewProjName + _T(".mdb");
if (!CopyFile(sourceFile,distFile,FALSE))
{
AfxMessageBox(_T("另存数据库失败 :") + distFile);
return;
}
sourceFile = projectBasePath + _T("\\") + projectTitle + _T(".grid");
distFile = pzNewBasePath + _T("\\") + pzNewProjName + _T(".grid");
if (!CopyFile(sourceFile,distFile,FALSE))
{
AfxMessageBox(_T("工程文件失败 :") + distFile);
return;
}
AfxMessageBox("项目成功另存到目录:"+pzNewBasePath);
}
}
参数说明: http://zhidao.baidu.com/question/183424347.html