當前位置:首頁 » 文件管理 » mfc文件夾復制

mfc文件夾復制

發布時間: 2024-09-10 21:00:50

A. mfc 如何復制文件到文件夾

主要有兩個難點:
1、如何選擇文件;
2、選擇好文件之後,如果復制;

1st、關於文件選擇,可參考下面這段代碼:
CString CDcPackerDlg::BootOpenDialog() //返回選擇的文件名稱
{
CString strFile = _T("");

CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.cfg)|*.cfg|All Files (*.*)|*.*||"), NULL);

if (dlgFile.DoModal())
{
strFile = dlgFile.GetPathName();
}

return strFile;
}

//載入文件按鈕
void CDcPackerDlg::OnBnClickedSelectdec()
{
// TODO: Add your control notification handler code here
m_strDescPath = ""; //類的成員變數

//"打開文件"對話框,選擇文件,返回其路徑
m_strDescPath = BootOpenDialog();
}

2nd、文件復制:
2.1 獲得程序目錄
CString strPath = "", strDir = "";
char filepath[MAX_PATH];
GetMoleFileName(NULL, filepath, MAX_PATH);
strDir.Format("%s", filepath);
strPath = strDir.Left(strDir.ReverseFind('\\'));

2.2 復制文件
在MFC下可以用CopyFile()函數,定義如下:
BOOL CopyFile(
LPCTSTR lpExistingFileName, //原文件地址,包括文件名
LPCTSTR lpNewFileName, ////目的文件地址,包括文件名
BOOL bFailIfExists //如果目的文件存在的操作
);

3rd、自己把上面給的代碼組裝一下,就可以滿足你的要求了。
打字不易,如滿意,望採納。

B. C++,MFC工程如何瀏覽一個文件,復制到另外一個文件夾

主要有兩個難點:
1、如何選擇文件;
2、選擇好文件之後,如果復制;

1st、關於文件選擇,可參考下面這段代碼:
CString CDcPackerDlg::BootOpenDialog() //返回選擇的文件名稱
{
CString strFile = _T("");

CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.cfg)|*.cfg|All Files (*.*)|*.*||"), NULL);

if (dlgFile.DoModal())
{
strFile = dlgFile.GetPathName();
}

return strFile;
}

//載入文件按鈕
void CDcPackerDlg::OnBnClickedSelectdec()
{
// TODO: Add your control notification handler code here
m_strDescPath = ""; //類的成員變數

//"打開文件"對話框,選擇文件,返回其路徑
m_strDescPath = BootOpenDialog();
}

2nd、文件復制:
2.1 獲得程序目錄
CString strPath = "", strDir = "";
char filepath[MAX_PATH];
GetMoleFileName(NULL, filepath, MAX_PATH);
strDir.Format("%s", filepath);
strPath = strDir.Left(strDir.ReverseFind('\\'));

2.2 復制文件
在MFC下可以用CopyFile()函數,定義如下:
BOOL CopyFile(
LPCTSTR lpExistingFileName, //原文件地址,包括文件名
LPCTSTR lpNewFileName, ////目的文件地址,包括文件名
BOOL bFailIfExists //如果目的文件存在的操作
);

3rd、自己把上面給的代碼組裝一下,就可以滿足你的要求了。

熱點內容
抖音社區源碼 發布:2025-09-16 16:12:48 瀏覽:133
酷派內置存儲空間不足 發布:2025-09-16 15:50:44 瀏覽:399
php設置編碼格式 發布:2025-09-16 15:20:04 瀏覽:612
php取兩位小數點 發布:2025-09-16 15:12:40 瀏覽:315
加密塊流加密 發布:2025-09-16 15:07:36 瀏覽:701
sqldeveloper導出表 發布:2025-09-16 15:07:33 瀏覽:366
xbox360ftp 發布:2025-09-16 14:45:34 瀏覽:851
火車站附近wifi密碼是多少 發布:2025-09-16 14:45:30 瀏覽:195
國家標准加密 發布:2025-09-16 14:45:27 瀏覽:954
php集成支付寶 發布:2025-09-16 14:05:28 瀏覽:723