批量重命名文件(c++)工具源码

用处

可去除文件名首尾括号
可批量获取文件名称

代码

将《 》去除   代码以.mp3文件示例 

#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include<fstream>  //ifstream
#include<string>     //包含getline()
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
 
int main(void)
{
	freopen("标题.txt","w",stdout);
	intptr_t Handle;
	struct _finddata_t FileInfo;
	string p;
	string path = "C:\\Users\\22389\\Desktop\\New folder (6)";
	if ((Handle = _findfirst(p.assign(path).append("\\*").c_str(), &FileInfo)) == -1)
		printf("没有找到匹配的项目\n");
	else
	{
		printf("%s\n", FileInfo.name);
		while (_findnext(Handle, &FileInfo) == 0)
			printf("%s*\n", FileInfo.name);
		_findclose(Handle);
	}
	//获取所有名称 
	cout << '|';
	return 0;
	//打结束flag
}
/* 作者:Dx__15;
   备注:若批量重命名 需搭配 “将标题文件重命名”使用
*/ 
#include <bits/stdc++.h>
using namespace std;

void renam(char a[],char b[]) 
{
	int result = rename(a,b);//将a命名为b
	if (result == 0) 
 	   	printf("文件重命名成功!\n");
	else 
   	 	printf("文件重命名失败!\n");
}

int main ()
{
	freopen("标题.txt","r",stdin);//打开标题 
	while(1)
	{
		char a[40],b[40];
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(a));
		int k=0;
		while(1)
		{
			char d=0;
			scanf("%c",&d);
			if(d=='*') 
			{
				d=getchar();
				break;
			}
			else a[k++]=d;
		 } 
		
		int size=strlen(a);
		for(int i=2;i<size-6;i++) b[i-2]=a[i];
		//可将i改为任何数  因为"《"长为2   所以这里是2 
		//减6是因为".mp3"占4格   4+2=6
		
		int x=size-8;
		b[x] = '.';
		b[x+1] = 'm';
		b[x+2] = 'p';
		b[x+3] = '3';
		// .mp3 是后缀名 可改为任意后缀
		// 如果 改为任意后缀 需要调整 i、x、x-n、i-n 
		
		if(a[0]=='|') break;// 扫描至结束flag 
		
		printf("%s\n",b);//显示当前任务 
		renam(a,b);
	}
}

/* 作者:Dx__15;
   备注:
   		1若批量重命名 需搭配 “获取标题”使用
   		2将 生成文件(.exe)和标题.txt 放入目标目录 
         点击 生成文件(.exe)即可 
*/ 

求关注 求点赞

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值