#include <stdio.h>
#include <io.h>
#include <string.h>
int scandir(void){
char path[200]="D:\\test";
char pathcpy[100];
char substr[100]="第"; //该字符串前的文字都去掉
char* new_filename;
char new_filepath[100];
int res;
// puts("请输入要查询的路径(不超过200字符)");
// scanf("%200s",path);
strcat(path,"/");
size_t path_len = strlen(path);
strcpy(new_filepath,path);
struct _finddata_t fa;
long handle;
if((handle = _findfirst(strcat(path,"*"),&fa)) == -1L){
printf("The Path %s is wrong!\n",path);
return 0;
}
int i=0;
int y;
while(_findnext(handle,&fa)==0){
if(!strcmp(fa.name,".")||!strcmp(fa.name,".."))continue;
new_filename=strstr(fa.name,substr);
if(!new_filename)continue;//如果找不到返回null 后面用strcpy就会出错
strcpy(path+path_len,fa.name);
strcpy(new_filepath+path_len,new_filename);
printf("%d:%s>>>>%s\n",++i,fa.name,new_filename);
res=rename(path,new_filepath);
if (res)puts("文件重命名失败!");
}
_findclose(handle);
return 0;
}
int main(void)
{
scandir();
return 0;
}
标签:批量,fa,int,文件名,filename,char,修改,new,path From: https://www.cnblogs.com/yuyanc/p/17615567.html