可根据需求进行相应修改,实现各种需求的文件名更改
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <sstream>
#include <io.h>
using namespace std;
void reNameFiles(string path)
{
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
static int i = 1;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,迭代
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
reNameFiles(p.assign(path).append("\\").append(fileinfo.name));
}
//如果不是,重命名
else
{
string temp = "";
string fileName =temp.append(fileinfo.name).c_str();
//获取文件名的后缀
string suffixName = fileName.substr(fileName.rfind(".") + 1, path.length());
//若目标后缀是vtt 进行重命名
if (suffixName == "vtt")
{
//获取不带后缀的文件名
string noSuffixName = fil