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

熱點內容
java下載伺服器文件 發布:2025-05-06 06:09:21 瀏覽:626
cpu配置過低是什麼意思 發布:2025-05-06 06:09:13 瀏覽:639
資料庫欄位命名 發布:2025-05-06 05:59:19 瀏覽:36
頁面源碼下載 發布:2025-05-06 05:51:29 瀏覽:134
勇士食堂安卓怎麼登錄 發布:2025-05-06 05:49:19 瀏覽:531
java三級 發布:2025-05-06 05:47:52 瀏覽:891
c語言沒聽課 發布:2025-05-06 05:29:46 瀏覽:416
潘多拉綁定伺服器ip 發布:2025-05-06 05:15:33 瀏覽:540
學通c語言的24堂課pdf 發布:2025-05-06 05:14:42 瀏覽:899
圓形文件夾 發布:2025-05-06 05:11:47 瀏覽:144