// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CModifyFilenamesDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CModifyFilenamesDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
// OnOK();
TCHAR szFind[MAX_PATH] = {0};
CString strPATH;
TCHAR szContain[MAX_PATH] = {0};
TCHAR szReplace[MAX_PATH] = {0};
CString strOriginalFileName;
CString strReplaceFileName;
CString strContain;
CString strReplace;
WIN32_FIND_DATA FindFileData;
GetDlgItemText(IDC_E_PATH, strPATH);
GetDlgItemText(IDC_E_CONTAIN_TEXT, strContain);
GetDlgItemText(IDC_E_REPLACE_TEXT, strReplace);
_tcscpy(szFind, strPATH.GetBuffer());
strPATH.ReleaseBuffer();
_tcscat(szFind, _T("\\*.*"));
HANDLE hFind=::FindFirstFile(szFind, &FindFileData);
if (INVALID_HANDLE_VALUE == hFind)
return;
while(TRUE)
{
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
}
else
{
CString strTemp;
// 替换文件名
strTemp.Format(_T("%s"), FindFileData.cFileName);
// 原始文件名
strOriginalFileName.Format(_T("%s\\%s"), strPATH, strTemp);
// 替换文件名
int num = strTemp.Replace(strContain, strReplace);
strReplaceFileName.Format(_T("%s\\%s"), strPATH, strTemp);
MoveFile( strOriginalFileName.GetBuffer(), strReplaceFileName.GetBuffer());
strReplaceFileName.ReleaseBuffer();
strOriginalFileName.ReleaseBuffer();
}
// 查找下一个文件
if (!FindNextFile(hFind, &FindFileData))
break;
}
FindClose(hFind);
}
void CModifyFilenamesDlg::OnBnClickedButton1()
{
CFileDialog dlg(TRUE,//TRUE是创建打开文件对话框,FALSE则创建的是保存文件对话框
_T(".*"),//默认的打开文件的类型
NULL,//默认打开的文件名
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,//打开只读文件
_T("(*.*)|*.*||"));//所有可以打开的文件类型
if(dlg.DoModal() == IDOK)
{
CString m_FilePath = dlg.GetPathName();取出文件路径
int nPos;
nPos = m_FilePath.ReverseFind('\\');
m_FilePath = m_FilePath.Left(nPos);
SetDlgItemText(IDC_E_PATH, m_FilePath);
}
// TODO: Add your control notification handler code here
}
void CModifyFilenamesDlg::OnDropFiles(HDROP hDropInfo)
{
// TODO: Add your message handler code here and/or call default
UINT count;
TCHAR filePath[200] = {0};
count = DragQueryFile(hDropInfo, 0, filePath, sizeof(filePath));
CString m_FilePath(filePath);
FILE* file = NULL;
file = _tfopen(filePath, _T("rb"));
if (file != NULL)
{
int nPos;
nPos = m_FilePath.ReverseFind('\\');
m_FilePath = m_FilePath.Left(nPos);
fclose(file);
}
SetDlgItemText(IDC_E_PATH, m_FilePath);
DragFinish(hDropInfo);
}
// the minimized window.
HCURSOR CModifyFilenamesDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CModifyFilenamesDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
// OnOK();
TCHAR szFind[MAX_PATH] = {0};
CString strPATH;
TCHAR szContain[MAX_PATH] = {0};
TCHAR szReplace[MAX_PATH] = {0};
CString strOriginalFileName;
CString strReplaceFileName;
CString strContain;
CString strReplace;
WIN32_FIND_DATA FindFileData;
GetDlgItemText(IDC_E_PATH, strPATH);
GetDlgItemText(IDC_E_CONTAIN_TEXT, strContain);
GetDlgItemText(IDC_E_REPLACE_TEXT, strReplace);
_tcscpy(szFind, strPATH.GetBuffer());
strPATH.ReleaseBuffer();
_tcscat(szFind, _T("\\*.*"));
HANDLE hFind=::FindFirstFile(szFind, &FindFileData);
if (INVALID_HANDLE_VALUE == hFind)
return;
while(TRUE)
{
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
}
else
{
CString strTemp;
// 替换文件名
strTemp.Format(_T("%s"), FindFileData.cFileName);
// 原始文件名
strOriginalFileName.Format(_T("%s\\%s"), strPATH, strTemp);
// 替换文件名
int num = strTemp.Replace(strContain, strReplace);
strReplaceFileName.Format(_T("%s\\%s"), strPATH, strTemp);
MoveFile( strOriginalFileName.GetBuffer(), strReplaceFileName.GetBuffer());
strReplaceFileName.ReleaseBuffer();
strOriginalFileName.ReleaseBuffer();
}
// 查找下一个文件
if (!FindNextFile(hFind, &FindFileData))
break;
}
FindClose(hFind);
}
void CModifyFilenamesDlg::OnBnClickedButton1()
{
CFileDialog dlg(TRUE,//TRUE是创建打开文件对话框,FALSE则创建的是保存文件对话框
_T(".*"),//默认的打开文件的类型
NULL,//默认打开的文件名
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,//打开只读文件
_T("(*.*)|*.*||"));//所有可以打开的文件类型
if(dlg.DoModal() == IDOK)
{
CString m_FilePath = dlg.GetPathName();取出文件路径
int nPos;
nPos = m_FilePath.ReverseFind('\\');
m_FilePath = m_FilePath.Left(nPos);
SetDlgItemText(IDC_E_PATH, m_FilePath);
}
// TODO: Add your control notification handler code here
}
void CModifyFilenamesDlg::OnDropFiles(HDROP hDropInfo)
{
// TODO: Add your message handler code here and/or call default
UINT count;
TCHAR filePath[200] = {0};
count = DragQueryFile(hDropInfo, 0, filePath, sizeof(filePath));
CString m_FilePath(filePath);
FILE* file = NULL;
file = _tfopen(filePath, _T("rb"));
if (file != NULL)
{
int nPos;
nPos = m_FilePath.ReverseFind('\\');
m_FilePath = m_FilePath.Left(nPos);
fclose(file);
}
SetDlgItemText(IDC_E_PATH, m_FilePath);
DragFinish(hDropInfo);
}