文件操作,涉及CFileFind ,CFileDialog CFile 类的操作。
///完成的功能是:把源目录下的文件拷贝到目标目录下面。
void CBackUpFilesDlg::BackFiles(CString soureFiles,CString detinFiles)
{
CFileFind find;
CString strPathFiles = soureFiles;
CStringArray strFileArray;
int bFind=0;
if ( strPathFiles.Right(1) != "//" )
strPathFiles += "//";
strPathFiles += "*.*";
bFind = find.FindFile( strPathFiles );
while ( bFind )
{
bFind = find.FindNextFile();
strFileArray.Add(find.GetFileName());
}
int count=strFileArray.GetSize();
int i=0;
///遍历数组,拷贝到目标目录
for(i=2;i<count;i++)
{
/*LPCTSTR pointerSource=(LPCTSTR)strPathFiles[i]
LPCTSTR pointerDestin=(LPCTSTR)strPathFiles[i];
CopyFile(pointerSource,pointerDestin,false);*/
CString sourceFile=(CString)strFileArray[i];
CString sourceFileName= this->m_CString_Source+"//"+sourceFile;
CString destinFileName=this->m_CString_Destin+"//"+sourceFile;
BOOL isCopySuccess=false;
isCopySuccess=CopyFile(sourceFileName,destinFileName,
///CFileDialog 的使用
CFileDialog fileDialog(true);
fileDialog.DoModal();
CString fileFullPath=fileDialog.GetPathName();
CString fileName=fileDialog.GetFileName();
int fullpathLength=fileFullPath.GetLength();
int fileNameLength=fileName.GetLength();
fileFullPath.Delete(fullpathLength-fileNameLength-1,fileNameLength+1);
this->m_CString_Source=fileFullPath;
this->m_CEdit_Source.SetSel(0,-1);
this->m_CEdit_Source.ReplaceSel(this->m_CString_Source);