📄 copyfiledlg.cpp
字号:
// CopyFileDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CopyFile.h"
#include "CopyFileDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCopyFileDlg dialog
CCopyFileDlg::CCopyFileDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCopyFileDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCopyFileDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCopyFileDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCopyFileDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCopyFileDlg, CDialog)
//{{AFX_MSG_MAP(CCopyFileDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton_FindAndCopy)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCopyFileDlg message handlers
BOOL CCopyFileDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CCopyFileDlg::OnButton_FindAndCopy()
{
// TODO: Add your control notification handler code here
WIN32_FIND_DATA FileData;
HANDLE hSearch;
BOOL bFinished = FALSE;
const int MAXPATH = 1024;
TCHAR szNewPath[MAXPATH];
TCHAR szDirPath[] = _T("\\New Files");
// TCHAR szSourcePath[] = _T("\\Storage Card");
TCHAR szSourcePath[] = _T("\\My Documents");
#if 1
if (CreateDirectory(_T("\\New Files"),NULL))
{
AfxMessageBox(_T("Creat Ok!"));
}
else
{
AfxMessageBox(_T("Creat Error!"));
}
#endif
#if 1
//search
lstrcat(szSourcePath, _T("\\"));
lstrcat(szSourcePath, _T("*.jpg"));
hSearch = FindFirstFile (szSourcePath, &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
AfxMessageBox(_T("NO Found Files"));
return ;
}
//copy
while (!bFinished)
{
lstrcpy(szNewPath,szDirPath);
lstrcat(szNewPath,_T("\\"));
lstrcat(szNewPath,FileData.cFileName);
if ( CopyFile ( FileData.cFileName,szNewPath,FALSE ) )
{
if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
{
SetFileAttributes(szNewPath,
FileData.dwFileAttributes | FILE_ATTRIBUTE_READONLY);
}
}
else
{
AfxMessageBox(_T("COPY FAILE!"));
}
if (!FindNextFile(hSearch,&FileData))
{
bFinished = TRUE;
if (GetLastError() == ERROR_NO_MORE_FILES)
{
AfxMessageBox(_T("Find ALL Files!"));
}
else
{
AfxMessageBox(_T("NO Find Next Files"));
}
}/* end of if (!FindNextFile(hSearch,&FileData))*/
}/* end of while (!bFinished) */
//close handle
if (!FindClose(hSearch))
{
AfxMessageBox(_T("Close handle faile!"));
}
#endif
}
void CCopyFileDlg::OnButton2()
{
// TODO: Add your control notification handler code here
// AfxMessageBox(_T("创建目录成功!"));
}
int CCopyFileDlg::SearchFile(TCHAR szPath)
{
#if 0
HANDLE hSearch;
BOOL bFinished = FALSE;
hSearch = FindFirstFile(_T("\\Storage Card\\*.gpg"),&FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
AfxMessageBox(_T("NO FIND FILES"));
}
else
while (!bFinished)
{
lstrcpy(szNewPath,szDirPath);
lstrcat(szNewPath,_T("\\"));
lstrcat(szNewPath,FileData.cFileName);
if (CopyFile(FileData.cFileName,szNewPath,FALSE))
{
if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED))
{
SetFileAttributes(szNewPath,
FileData.dwFileAttributes | FILE_ATTRIBUTE_READONLY);
}
}/* end of if (CopyFile(FileData.cFileName,szNewPath,FALSE))*/
else
{
AfxMessageBox(_T("COPY FAILE!"));
}
if (!FindNextFile(hSearch,&FileData))
{
bFinished = TRUE;
if (GetLastError() == ERROR_NO_MORE_FILES)
{
AfxMessageBox(_T("Find ALL Files!"));
}
else
{
AfxMessageBox(_T("NO Find Next Files"));
}
}/* end of if (!FindNextFile(hSearch,&FileData))*/
}/* end of while (!bFinished) */
if (!FindClose(hSearch))
{
AfxMessageBox(_T("Close handle faile!"));
}
return 0;
#endif
return 0;
}
void CCopyFileDlg::CopyFiles()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -