核心代码实现如下(递归实现):
void Widget::Recursion(const QString& strPath)
{
QList<QString> stDir;
QString strName;
if( strPath.isEmpty() )
{
return;
}
QDir dir(strPath);
QFileInfoList fInfoList = dir.entryInfoList(QDir::Dirs|QDir::Files|QDir::NoDotAndDotDot);
QFileInfoList::iterator it = fInfoList.begin();
for(; it!=fInfoList.end(); ++it)
{
bool ret = it->isDir();
strName = it->fileName();
if( it->fileName().contains(m_strDel) && m_radioDel.isChecked() )
{
strName = strName.remove(m_strDel);
dir.rename(it->fileName(), strName);
}
if( m_radioRep.isChecked() )
{
if( ret )
{
strName += m_strDel;
}
else
{
strName = strName.insert(strName.lastIndexOf("."), m_strDel);
}
dir.rename(it->fileName(), strName);
}
if( ret )
{
stDir.append(strName);
}
}
QList<QString>::iterator itDir = stDir.begin();
for(; itDir!=stDir.end(); ++itDir)
{
strName = strPath + "/" + *itDir;
Recursion(strName);
}
}
处理前情况:
小工具实现界面:
处理后的截图:
小工具可执行程序链接:https://download.csdn.net/download/weixin_41937297/84253532