一、建立工程,添加相应控件,给各控件置变量。
建立工程asp文件生成器,选择对话框类型,加入控件:IDC_EDIT1、变量为CString m_address;IDC_LIST1、变量为CListBox m_list;IDC_BUTTON1,属性为:浏览,IDC_BUTTON2,属性为:修改全部文件名。
二、将文件目录到添加列表框
双击IDC_BUTTON1 加入代码如下:
void CAspDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char path[500];
BROWSEINFO bi;
ITEMIDLIST * pidl;
bi.hwndOwner =this->GetSafeHwnd();
bi.iImage =0;
bi.lParam =0;
bi.lpfn =0;
bi.lpszTitle ="请选择文件夹";
bi.pidlRoot =0;
bi.pszDisplayName =0;
bi.ulFlags =BIF_RETURNONLYFSDIRS;
pidl=SHBrowseForFolder(&bi);
if (SHGetPathFromIDList(pidl,path)==TRUE)
{
m_address =path;
UpdateData(false);
CString path1 = m_address+"\\*.jpg";
CListBox* listbox1 = (CListBox*)GetDlgItem(IDC_LIST1);
listbox1->Dir(DDL_DIRECTORY|DDL_SYSTEM,path1);
}
}
三、为文件名改名添加相应代码
双击IDC_BUTTON2 加入代码如下:
void CAspDlg::OnButton2()
{
// TODO: Add your control notification handler code here
if(m_address!=_T(""))
{
int count = m_list.GetCount();
for (int i=0;i < count ;i++)
{
CString strImageName;
strImageName.Empty();
strImageName.Format(_T("%d"),i+1);
strImageName ="image" +strImageName + ".jpg";
CString strImageFileName;
((CListBox *)GetDlgItem(IDC_LIST1))->GetText(i, strImageFileName);
CString strOldImage = m_address + "\\" + strImageFileName;
CString strNewImage = m_address + "\\" + strImageName;
MoveFile(strOldImage,strNewImage);
}
while(m_list.GetCount())
m_list.DeleteString(0);
CString path1 = m_address+"\\*.jpg";
CListBox* listbox1 = (CListBox*)GetDlgItem(IDC_LIST1);
listbox1->Dir(DDL_DIRECTORY|DDL_SYSTEM,path1);
}
else AfxMessageBox("请输入文件路径!");
}
|