Advertisement
Guest User

demon

a guest
May 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. #include<windows.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. int main(){
  6.     WIN32_FIND_DATA FindFileData;
  7.     HANDLE hf=FindFirstFile("D:\\proc\\*", &FindFileData);
  8.     CHAR fileNames[200][MAX_PATH];
  9.     INT i=0;
  10.     if (hf==INVALID_HANDLE_VALUE)
  11.         {
  12.         puts("Path not found");
  13.         return 1;
  14.         }
  15.             do{
  16.                 strcpy(fileNames[i], FindFileData.cFileName);
  17.                 //puts(fileNames[i]);
  18.                 ++i;
  19.             }
  20.             while (FindNextFile(hf,&FindFileData));
  21.      
  22.         FindClose(hf);
  23.  
  24.    
  25.  
  26.     char name[] = "D:\\proc\\";
  27.    
  28.     int k=2;
  29.     CHAR fileNames1[200][MAX_PATH];
  30.     INT i1=0;
  31.     for(k=2; k<9; k++)
  32.     {
  33.    
  34.     char* buff = calloc(strlen(name) + strlen(fileNames[k]) + 1, 1);
  35.     strcat(buff, name);
  36.     strcat(buff, fileNames[k]);
  37.     strcat(buff, "\\");
  38.     char* temp = calloc(buff + 1, 1);
  39.     strncpy(temp, buff, strlen(buff));
  40.     strcat(buff, "*");
  41.    
  42.     hf=FindFirstFile(buff, &FindFileData);
  43.    
  44.    
  45.     if (hf==INVALID_HANDLE_VALUE)
  46.         {
  47.         puts("Path not found");
  48.         return 1;
  49.         }  
  50.             do{
  51.                 strcpy(fileNames1[i1], FindFileData.cFileName);
  52.                 //puts(fileNames1[i1]);
  53.                 ++i1;
  54.             }
  55.             while (FindNextFile(hf,&FindFileData));
  56.      
  57.         FindClose(hf);
  58.      
  59.     char s[100];
  60.    
  61.     char* buff1 = calloc(strlen(temp) + strlen("temp.txt") + 1, 1);
  62.     strcat(buff1, temp);
  63.     strcat(buff1, "temp.txt");
  64.    
  65.    FILE* f1 = fopen(buff1, "r");
  66.  
  67.    for(i=0;i<4;i++)
  68.    {
  69.     fgets(s,128,f1);
  70.     if(i!=2)
  71.     printf("%s", s);   
  72.    }
  73.     printf("\n");
  74.     putchar('\n');   
  75. }
  76.      
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement