File classification According to the file name specified in the TXT file:
//file Classification According to the file name specified in the TXT file#include<stdio.h>#include<stdlib.h>#include<malloc.h>#include<windows.h>#include<io.h>#include<direct.h>#include<string.h>voidRemove_end_char (Chara[]) { intL =strlen (a); for(inti =0; I <= L; i++) if(A[i] = ='\ n') {A[i]=' /'; }}Char* Str_join (Char*S1,Char*S2) { Char*result = (Char*)malloc(strlen (S1) + strlen (S2) +1); if(Result = =NULL) Exit (1); strcpy (result, S1); strcat (result, S2); returnresult;}intMain () {CharFilename[] ="E:\\name.txt"; FILE*FP; Charstrline[260]; if(fp = fopen (filename,"R")) ==NULL) {printf ("Open File error!"); return-1; } LongHandle; struct_finddata_t FileInfo; intSame_num =0; Char*New_picture_file; //need to modify_chdir ("e:\\"); if(Handle = _findfirst ("*.jpg", &fileinfo)) = =-1L) {printf ("no matching files found \ n"); } Else { while(!feof (FP)) {fgets (StrLine,260, FP); Remove_end_char (StrLine); //same file name if(!strcmp (Fileinfo.name, StrLine)) {printf ("%s\n", StrLine); Same_num++; //need to modifyNew_picture_file = Str_join ("e:\\", StrLine); Rename (StrLine, new_picture_file); } } //Reset file pointer to file headerRewind (FP); while(_findnext (Handle, &fileinfo) = =0) { while(!feof (FP)) {fgets (StrLine,260, FP); Remove_end_char (StrLine); //same file name if(!strcmp (Fileinfo.name, StrLine)) {printf ("%s\n", StrLine); Same_num++; //need to modifyNew_picture_file = Str_join ("e:\\", StrLine); Rename (StrLine, new_picture_file); //Neither of these can be used, but the parameters haven't been matched.//system ("copy"); //CopyFile ();}} rewind (FP); }} printf ("the number of identical images is:%d\n", Same_num); Fclose (FP); _findclose (Handle); return 0;}
File classification According to the file name specified in the TXT file