當前位置:首頁 » 文件管理 » 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、自己把上面給的代碼組裝一下,就可以滿足你的要求了。

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:631
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:360
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:76
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:301
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:789
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:339
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:204
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:804
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:358
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:584