Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dirent.h>
- #include <errno.h>
- #include <unistd.h>
- #include <ctype.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <regex.h>
- #define BUF 255
- typedef struct DUPL {
- char* name_of_file;
- char** ways_of_file;
- int quant;
- }DUPL;
- typedef struct DUPL_ARR {
- DUPL* files;
- int quant_dif_files;
- } DUPL_ARR;
- int checkingDir(char* way, DUPL_ARR* files) {
- //char* begin_way = (char*)malloc(strlen(way) * sizeof(char));
- //memmove(begin_way, way, (strlen(way) + 1) * sizeof(char));
- DIR* dir = opendir(way);
- struct dirent* cur = readdir(dir);
- //char* path = (char*)calloc(strlen(cur->d_name)+strlen(way)+4, sizeof(char));
- while (cur) {
- if (strcmp(cur->d_name, ".") && strcmp(cur->d_name, "..")) {
- if (cur->d_type == DT_DIR) {
- char curFile[256];
- strcpy(curFile, cur);
- strcat(curFile, "/");
- strcat(curFile, cur->d_name);
- checkingDir(curFile, files);
- }
- else {
- for (int i = 0; i < files->quant_dif_files; i++) {
- if (!strcmp(files->files[i]->name_of_file, cur->d_name)) {
- files->files[i]->ways_of_file = realloc(files->files[i]->ways_of_file, files->files[i]->quant]);
- files->files[i]->quant++;
- break;
- }
- }
- if (strcmp(files->files[i]->name_of_file, cur->d_name) {
- files->files = realloc(files->files, files->quant_dif_files + 1);
- strcpy(files->files[files->quant_dif_files], cur->d_name);
- files->quant_dif_files++;
- }
- }
- }
- //free(path);
- cur = readdir(dir);
- }
- free(path);
- closedir(dir);
- return quant;
- }
- int main() {
- char* name = (char*)malloc(BUF * sizeof(char));
- getcwd(name, BUF); // получаем имя текущего каталога
- DUPL_ARR* folders;
- folders->quant_dif_files = 0;
- for (int i = 0; i < BUF; i++) {
- folders->files[i].quant = 0;
- folders->files[i].name_of_file = (char*)calloc(BUF, sizeof(char));
- folders->files[i].ways_of_file = (char*)calloc(BUF, sizeof(char));
- }
- printf("Дубликатов: %d\n", checkingDir(name, &folders));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement