#define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<string.h>#include<io.h>intPROTECTSTR (Const Char*name,Char*newname,intLen) { intErrMsg =0; /*first find the number 5 or 6, next to determine whether the adjacent 3 characters are numbers, take out the number*/ inti =0; /*STRCHR ()*/ Char* Temp = (Char*) name; /*Number of episodes*/ Chartemp2[Ten] = {0 }; /*file Format*/ Chartemp3[Ten] = {0 }; while(1) {Temp= STRCHR (temp,'6'); //if (temp==null)//temp = STRCHR (temp, ' 6 '); if(temp = =NULL)return-1; if(* (temp +1) >='0'&&* (temp +1) <='9'&&* (temp +2) >='0'&&* (temp +2) <='9') { //indicates that 3 characters in a row are numbersstrncpy (TEMP2, temp,3); Temp= STRCHR (temp,'.'); strcpy (Temp3, temp); Break; } temp+=1; } sprintf (NewName,"f:/Warehouse 1/naruto/naruto%s%s", Temp2, Temp3); returnerrmsg;}voidMain () {
//How to read files in directory struct_finddata_t files; intFile_handle; File_handle= _findfirst ("f:/Warehouse 1/naruto/*", &files); if(File_handle = =-1) {printf ("error\n"); return ; } inti =0; Charoldname[1024x768] = {0 }; Charnewname[1024x768] = {0 }; Do{memset (oldname,0,sizeof(oldname)); memset (NewName,0,sizeof(newname)); //printf ("%s \ n", files.name);sprintf (Oldname,"f:/Warehouse 1/Naruto/%s", Files.name); if(Protectstr (Files.name, NewName, strlen (files.name)) = =0) Rename (oldname, newname); I++; } while(0= = _findnext (File_handle, &files)); _findclose (File_handle); //char newname[1024] = {0}; //protectstr (names, newname, strlen (names)); //printf ("%s\n", newname);System"Pause");}
C Language Auto-modify file name applet