SHARE
TWEET

Untitled

a guest May 24th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dirent.h>
  5. #include <errno.h>
  6. #include <unistd.h>
  7. #include <ctype.h>
  8. #include <sys/stat.h>
  9. #include <sys/types.h>
  10. #include <regex.h>
  11.  
  12. #define BUF 255
  13.  
  14. typedef struct DUPL {
  15.     char* name_of_file;
  16.     char** ways_of_file;
  17.     int quant;
  18. }DUPL;
  19.  
  20. typedef struct DUPL_ARR {
  21.     DUPL* files;
  22.     int quant_dif_files;
  23. } DUPL_ARR;
  24.  
  25. int checkingDir(char* way, DUPL_ARR* files) {
  26.     //char* begin_way = (char*)malloc(strlen(way) * sizeof(char));
  27.     //memmove(begin_way, way, (strlen(way) + 1) * sizeof(char));
  28.     DIR* dir = opendir(way);
  29.     struct dirent* cur = readdir(dir);
  30.     //char* path = (char*)calloc(strlen(cur->d_name)+strlen(way)+4, sizeof(char));
  31.     while (cur) {
  32.         if (strcmp(cur->d_name, ".") && strcmp(cur->d_name, "..")) {
  33.             if (cur->d_type == DT_DIR) {
  34.                 char curFile[256];
  35.                 strcpy(curFile, cur);
  36.                 strcat(curFile, "/");
  37.                 strcat(curFile, cur->d_name);
  38.                 checkingDir(curFile, files);
  39.             }
  40.             else {
  41.                 for (int i = 0; i < files->quant_dif_files; i++) {
  42.                     if (!strcmp(files->files[i]->name_of_file, cur->d_name)) {
  43.                         files->files[i]->ways_of_file = realloc(files->files[i]->ways_of_file, files->files[i]->quant]);
  44.                         files->files[i]->quant++;
  45.                         break;
  46.                     }
  47.                    
  48.                 }
  49.                 if (strcmp(files->files[i]->name_of_file, cur->d_name) {
  50.                     files->files = realloc(files->files, files->quant_dif_files + 1);
  51.                     strcpy(files->files[files->quant_dif_files], cur->d_name);
  52.                     files->quant_dif_files++;
  53.                 }
  54.             }
  55.         }
  56.         //free(path);
  57.         cur = readdir(dir);
  58.     }
  59.    
  60.     free(path);
  61.     closedir(dir);
  62.     return quant;
  63. }
  64.  
  65. int main() {
  66.  
  67.     char* name = (char*)malloc(BUF * sizeof(char));
  68.     getcwd(name, BUF);  // получаем имя текущего каталога
  69.     DUPL_ARR* folders;
  70.     folders->quant_dif_files = 0;
  71.     for (int i = 0; i < BUF; i++) {
  72.         folders->files[i].quant = 0;
  73.         folders->files[i].name_of_file = (char*)calloc(BUF, sizeof(char));
  74.         folders->files[i].ways_of_file = (char*)calloc(BUF, sizeof(char));
  75.     }
  76.  
  77.     printf("Дубликатов: %d\n", checkingDir(name, &folders));
  78.  
  79.     return 0;
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top