1. Open a file and copy the content to another file:
2. open the file to be copied:
CFileDialog dlg (TRUE, "*", "", OFN_ALLOWMULTISELECT, NULL );
If (IDOK = dlg. DoModal ())
{
CString str = dlg. GetPathName ();
SetDlgItemText (IDC_EDIT1, str );
}
3. Implementation:
Void CCopyFileDlg: OnCopyfile ()
{
// TODO: Add your control notification handler code here
CString filename1 = "";
CString filename2 = "";
GetDlgItemText (IDC_EDIT1, filename1 );
CFileDialog dlg (false, "", "", OFN_ALLOWMULTISELECT, NULL );
If (IDOK = dlg. DoModal ())
{
Filename2 = dlg. GetFileName ();
CFile file1;
CFile file2;
File1.Open (filename1, CFile: modeReadWrite );
File2.Open (filename2, CFile: modeCreate | CFile: modeReadWrite );
Char * c;
C = new char [file1.GetLength ()];
File1.Read (c, file1.GetLength ());
File2.Write (c, file1.GetLength ());
File1.Close ();
File2.Close ();
// Delete c;
AfxMessageBox ("file copied successfully ");
}
}