如上图所示选择了文件类型后,点击“选择路径”,选择了一个文件夹,然后在列表控件中显示搜到的文件名,想把这些文件名后面添加一个密级,像0: 不改名;1:“公开”等,举例:上下拉电阻的作用.pdf变成上下拉电阻的作用(公开).pdf,让操作者在选择了Combox 下拉列表控件的某一项之后,点击“重命名”按钮后,实现如上的操作。这里还有一个要求就是搜出来文件后,把所有的文件的文件名都修改喽,之后根据需要多选某些特定的文件名,实现对这些文件的文件名的标密,请问实现这些功能应该怎么编程?
解决方案 »
- 在线等:vs2005与vc6区别及turbc与vc6的区别
- 如何得到网站图标?
- 问一些p2p流媒体直播的问题
- 请教关于用VC编程时自动提示的问题??
- _ConnectionPtr m_pConnection在MFC常规DLL中m_pConnection.Release()失败!(在线等待,可出到1000分)
- UDP的问题
- 想改鼠标移到button上的cur,但没成功。
- Mime filter技术 的疑问,高手请进!
- __declspec(selectany) ATL::_ATL_OBJMAP_ENTRY ... 什么意思?
- 程序做了,要在另一台没装过VC的机器上用,程序里用到ADO,应该怎么做呢?
- vc 打印问题
- pIUnknown->QueryInterface(const IID& iid, void** ppv)中第一参数如何理解
百度搜“bat批处理改名”
dir 列出文件名
复制到excel里
用excel的文本函数
前面加上ren XXX 新文件名,拖拉
在贴到.bat文件里面
{
//std::vector<FileInfo>fileList;
std::string szFind(lpPath);
WIN32_FIND_DATA FindFileData;
szFind+=_T("\\*.*");
HANDLE hFind=::FindFirstFile(szFind.c_str(),&FindFileData); //这里用到了szFind
if(INVALID_HANDLE_VALUE==hFind) return;
do//while(1)
{
if(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) //判断
{//dir 目录在列表中可以双击打开,不要递归!
if(FindFileData.cFileName[0]!='.')
{
std::string szPath(lpPath);
szPath+=_T("\\");
szPath+=FindFileData.cFileName;
TRACE1("%s\n",szPath.c_str());
find(szPath.c_str(),FileList); //自注:这里小写的fileList不行。这一句是递归。
}
}
else
{ std::string strFileName=FindFileData.cFileName;//文件名
suffixStr=strFileName.substr(strFileName.find_last_of('.')+1); //这里的后缀就是所有文件类型的后缀,下面的文件是所有类型的文件的显示。
if(std::regex_match(suffixStr,suffixStr1))
{ FILETIME ft=FindFileData.ftCreationTime; //取得创建时间
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //转换成本地时间
FileTimeToSystemTime(&ft,&st); //在这句之前加上上一句,就不用再小时那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京时间*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //文件全路径名
FileInfo fi; //自注:结构变量不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:这句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
else if(suffixStr==suffixStr2)
{
FILETIME ft=FindFileData.ftCreationTime; //取得创建时间
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //转换成本地时间
FileTimeToSystemTime(&ft,&st); //在这句之前加上上一句,就不用再小时那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京时间*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //文件全路径名
FileInfo fi; //自注:结构变量不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:这句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
else if(std::regex_match(suffixStr,suffixStr3))
{
FILETIME ft=FindFileData.ftCreationTime; //取得创建时间
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //转换成本地时间
FileTimeToSystemTime(&ft,&st); //在这句之前加上上一句,就不用再小时那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京时间*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //文件全路径名
FileInfo fi; //自注:结构变量不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:这句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
else if(std::regex_match(suffixStr,suffixStr4))
{
FILETIME ft=FindFileData.ftCreationTime; //取得创建时间
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //转换成本地时间
FileTimeToSystemTime(&ft,&st); //在这句之前加上上一句,就不用再小时那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京时间*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //文件全路径名
FileInfo fi; //自注:结构变量不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:这句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
else if(suffixStr==suffixStr5)
{
FILETIME ft=FindFileData.ftCreationTime; //取得创建时间
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //转换成本地时间
FileTimeToSystemTime(&ft,&st); //在这句之前加上上一句,就不用再小时那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京时间*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //文件全路径名
FileInfo fi; //自注:结构变量不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:这句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
}
}while(::FindNextFile(hFind,&FindFileData));
// getchar();
}
是对这段程序进行修改,就可实现我前面提到的功能了吗?还是又需要别的程序,请指教。
而读写 fileList 要 快得多 !
CString name=m_list.GetItemText(nSelectedItem,1);
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));
CString path=m_list.GetItemText(nSelectedItem,3);
CStringArray ExeName;
char fullname[MAX_PATH];
strcpy(fullname,(LPTSTR)(LPCTSTR)path);
strcat(fullname,"\\");
strcat(fullname,(LPTSTR)(LPCTSTR)name);
afxDump << fullname << "\n";
fileList see "FillList"
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));是得到扩展名吧?
CStringArray ExeName是干什么的?
然后 改名 。
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));
另有它用, 注意 “机密” 在 ext 前。
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));干什么用?为什么不是“绝密”在ext前?
再 合并成 新 文件名 。
void CShowdirDlg::OnButton4()
{
// TODO: Add your control notification handler code here
POSITION pos = m_list.GetFirstSelectedItemPosition();
int nSelectedItem = -1;
while (pos != NULL)
{
nSelectedItem = m_list.GetNextSelectedItem(pos);
CString name = m_list.GetItemText(nSelectedItem,1);
CString path = m_list.GetItemText(nSelectedItem,3);
CString extame=name.Right(name.GetLength()-name.ReverseFind('.'));
CString pureName=name.Left(name.ReverseFind('.'));
CString newName=path;
newName += "\\";
newName += pureName;
newName += "机密";// 增加的
newName += extame;
AfxMessageBox(newName);
}
}
假设为A列,然后在B列内用公式B1=“ren ”& A1 & “ ” & A1 & “(公开)”
复制出来,粘贴到记事本中,存为bat文件
要 即 newName += "机密";// 增加的
是 m_cmb 当前 选择项 (m_cmb。GetWindowText(),即 其 edit 的 内容)
就是用户 选择 密级,你那个 cmb 不要 1.6 ,直接 就是 “机密“ 要不然 必须 去除 ‘1“ ’
用户 选择 密级 后 cmb 的 edit 显示 响应 密级 如 “机密“
newName += "机密";
变成
newName += m_cmb.GetWindowText() ;//
0: 有什么用 ?
不更改 又有 什么用 ?"1: 公开"
分 左右 2部分 ,取 右部 即可, 分割 标记 是 tab (09)或者 空格 (0x20)
用 Find (“ ”)或 ReverseFind (' ')
{
CString cmbName="1: 公开";// 5 spaces !
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
} 调用
CString sl=GetSecirityLevel();
其他 密级 就是 CString cmbName=m_cmb.GetWindowText() ;// "1: 公开";// 5 spaces !
int at=cmbName.ReverseFind(' ');// c从 右到左 找到 第一个 空格 的 位置 at。CString sl=GetSecirityLevel();
newName += sl ;// "机密";
CString cmbName="1: 公开";// 5 spaces !
改为CString cmbName=m_cmb.GetWindowText() ;即可,是吧?
// rename
CString CShowdirDlg::GetSecurityLevel()
{
CString cmbName;
m_Cmb1.GetWindowText(cmbName);//"1: 公开";
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
}
//
void CShowdirDlg::OnButton4()
{
// TODO: Add your control notification handler code here
CString sl=GetSecurityLevel();
POSITION pos = m_list.GetFirstSelectedItemPosition();
int nSelectedItem = -1;
while (pos != NULL)
{
nSelectedItem = m_list.GetNextSelectedItem(pos);
CString name = m_list.GetItemText(nSelectedItem,1);
CString path = m_list.GetItemText(nSelectedItem,3);
CString extname=name.Right(name.GetLength()-name.ReverseFind('.'));
CString pureName=name.Left(name.ReverseFind('.'));
CString newName=path;
newName += "\\";
newName += pureName;
newName += sl;// "机密";// 增加的
newName += extname;
AfxMessageBox(path + "\\"+ name + " To " + newName);
// CFile::Rename(path + "\\"+ name, newName );
}
}
CString CShowdirDlg::GetSecurityLevel()
{
CString cmbName;
m_Cmb1.GetWindowText(cmbName);//"1: 公开";
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
}
//这个函数是不是就是应该写到我VC2010程序的void XXXDlg:: OnCbnselchangeCombo()处呢?
因为 CString sl=GetSecurityLevel(); 是第一句 (不在while内),以后所有list的多选项 会用同一个 密级 改名
{
//ToD:在此添加控件通知处理程序代码
}
这里针对我需要实现的功能,需要写些什么呢?
还有请问:while以下的语句是什么意思,看不懂啊。
m_list 属性应该 是 多选。
用户 操作 如下 , 移动 鼠标 在 list 界面中 选择 任意多 项,(或 再改变 密级),点击 “Rename”, 那么 这批 文件就 同时 改名 到 一个 密级。
{
UINT nCount=fileList.size(); //得到控件的行数 总的文件个数。
UINT i;
//int pageNo=1;
Start=pageSize*(pageNo-1);
End=pageSize*pageNo;
CString empty; //难道是这里定义错了?
CString name;
CString time;
CString fpath;
mlist.LockWindowUpdate();
mlist.DeleteAllItems(); //要想实现翻页效果这句必不可少。
for(i=Start;i<End;i++) //改成i=0;i<50也还是不行,这里不是逻辑出了问题,而是其它的问题。
{
if(i>=nCount)break;
empty.Format(_T("%d"),i+1);
int nRow=mlist.InsertItem(i,empty); //这句话什么意思?
afxDump<<nRow<<"\n"; //这句对翻页没有影响
name.Format(_T("%s\n"),fileList[i].szFileName.c_str());
mlist.SetItemText(nRow,1,name); //插入列 自注:从这里开始程序就不对了,这句还是对的
time.Format(_T("%s\n"),fileList[i].szCreateTime.c_str());
mlist.SetItemText(nRow,2,time);
fpath.Format(_T("%s\n"),fileList[i].szFilePath.c_str()); //不影响翻页
mlist.SetItemText(nRow,3,fpath);
}
mlist.UnlockWindowUpdate();
// getchar();
}
void CresecretDlg::OnCbnSelchangeCombo()
{
// TODO: 在此添加控件通知处理程序代码
}CString CresecretDlg::GetSecurityLevel()
{
CString cmbName;
mComeboBox.GetWindowText(cmbName);//"1: 公开";
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
} void CresecretDlg::OnBnClickedButton4()
{
// TODO: 在此添加控件通知处理程序代码
CString sl=GetSecurityLevel();
POSITION pos = mlist.GetFirstSelectedItemPosition();
int nSelectedItem = -1;
while (pos!=NULL)
{
nSelectedItem = mlist.GetNextSelectedItem(pos);
CString name = mlist.GetItemText(nSelectedItem,1);
CString path = mlist.GetItemText(nSelectedItem,3);
CString extname=name.Right(name.GetLength()-name.ReverseFind('.'));
CString pureName=name.Left(name.ReverseFind('.'));
CString newName=path;
newName += "\\";
newName += pureName;
newName += sl;// "机密";// 增加的
newName += extname;
AfxMessageBox(path + "\\"+ name + " To " + newName);
// CFile::Rename(path + "\\"+ name, newName );
}
}
这两段程序中都有CString变量,变量相同,有没有冲突啊?我这些程序这么写被证实有问题,因为没有在文件名后面添加(公开),(内部),(秘密)等密级,请问是怎么回事。
概念错误 !
CString变量 ! CString 是 某变量 的 类型,不是 变量 , 如 int 是 整数 类型, 不是 整数 变量 !
mComeboBox.GetWindowText(cmbName);
检查 cmbName 是否 空 : if(cmbName.IsEmpty()) return CString(错误);在 rename 前 要 选择 mComeboBox