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

熱點內容
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:938
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:195
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:55
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:748
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:652
如何查看資料庫的版本 發布:2025-10-20 07:29:12 瀏覽:689
你的消息密碼是多少 發布:2025-10-20 07:23:37 瀏覽:248
ps2020不出現存儲路徑 發布:2025-10-20 07:18:39 瀏覽:156
python網站搭建 發布:2025-10-20 07:18:38 瀏覽:932
資料上傳口 發布:2025-10-20 06:08:50 瀏覽:387