SHARE
TWEET

for pasha

shadeyourself Jun 2nd, 2020 961 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <dirent.h>
  4. #include <string.h>
  5. #include <sys/stat.h>
  6. #include <stdlib.h>
  7.  
  8. int ifAvi(const char * filePath);
  9. int getSize(const char * filePath);
  10. int ifSame(const char * firsFilePath, const char * secondFilePath);
  11. void  aviCount(const char * dir,  int * aviAmount);
  12. void getAviPathes(const char * dir,  char ** aviPathes);
  13.  
  14.  
  15. //C:/Users/m video/Desktop/videos
  16. int main(){
  17.     char startDir[PATH_MAX+1], finishDir[PATH_MAX+1];
  18.     int aviAmount = 0;
  19.  
  20.     gets(startDir);
  21.     gets(finishDir);
  22.  
  23.     printf("-------------------------\n");
  24.  
  25.     strcat(finishDir, "/");
  26.     strcat(finishDir, "avis");
  27.  
  28.     //mkdir(finishDir);
  29.  
  30.     aviCount(startDir, &aviAmount);
  31.     printf("%d\n", aviAmount);
  32.  
  33.     char *aviPathes[aviAmount];
  34.     for(int i;i<aviAmount;i++)
  35.         aviPathes[i] = (char*)malloc(sizeof(char)*(PATH_MAX + 1));
  36.  
  37.     getAviPathes(startDir, aviPathes);
  38.  
  39.     printf("-------------------------\n");
  40.  
  41.    
  42.  
  43.     //for(int i = 0;i<aviAmount;i++)
  44.         //printf("%s\n", aviPathes);
  45.  
  46.     return 0;
  47. }
  48. //C:/Users/m video/Desktop/videos
  49. int getSize(const char * filePath){
  50.     int size;
  51.  
  52.     FILE * f = fopen(filePath, "r");
  53.     if(!f)return -1;
  54.  
  55.     fseek(f, 0L, SEEK_END);
  56.     size = ftell(f);
  57.  
  58.     fclose(f);
  59.  
  60.     return size;
  61. }
  62. //C:/Users/m video/Desktop/videos
  63. int ifAvi(const char * filePath){
  64.     FILE * f = fopen(filePath, "rb");
  65.     if(!f) return -1;
  66.  
  67.     char buf[13];
  68.     size_t result = fread(buf, 1, 12, f);
  69.  
  70.     if(result < 12) return 0;
  71.  
  72.     if(buf[0] != 'R') return 0;
  73.     if(buf[1] != 'I') return 0;
  74.     if(buf[2] != 'F') return 0;
  75.     if(buf[3] != 'F') return 0;
  76.     if(buf[8] != 'A') return 0;
  77.     if(buf[9] != 'V') return 0;
  78.     if(buf[10] != 'I') return 0;
  79.  
  80.     fclose(f);
  81.     return 1;
  82. }
  83. //C:/Users/m video/Desktop/videos
  84. int ifSame(const char * firsFilePath, const char * secondFilePath){
  85.     FILE * fisrtFile = fopen(firsFilePath, "r");
  86.     if(!fisrtFile) return -1;
  87.  
  88.     FILE * secondFile = fopen(secondFilePath, "r");
  89.     if(!secondFile) return -1;
  90.  
  91.     int firstFileSize = getSize(firsFilePath);
  92.     int secondFileSize = getSize(secondFilePath);
  93.     char first;
  94.     char second;
  95.  
  96.     if(firstFileSize != secondFileSize) return 0;
  97.  
  98.     for(int i; i<firstFileSize; i++){
  99.         first = fgetc(fisrtFile);
  100.         second = fgetc(secondFile);
  101.         if(first!=second) return 0;
  102.     }
  103.     return 1;
  104. }
  105. //C:/Users/m video/Desktop/videos
  106. void aviCount(const char * dir, int * aviAmount){
  107.     DIR *dp;
  108.     if((dp = opendir(dir)) == NULL) {
  109.         printf("cannot open directory\n");
  110.         return;
  111.     }
  112.  
  113.     char currentPath[PATH_MAX+1];
  114.  
  115.     struct dirent *entry;
  116.     struct stat statbuf;
  117.  
  118.     chdir(dir);
  119.     while((entry = readdir(dp)) != NULL) {
  120.  
  121.         strcpy(currentPath, dir);
  122.         strcat(currentPath, "/");
  123.         strcat(currentPath, entry->d_name);
  124.  
  125.         stat(entry->d_name,&statbuf);
  126.         if(S_ISDIR(statbuf.st_mode)) {
  127.             if(strcmp(".",entry->d_name) == 0 || strcmp("..",entry->d_name) == 0 || strcmp("avis",entry->d_name) == 0)
  128.                 continue;
  129.             aviCount(currentPath, aviAmount);
  130.         }
  131.         if(ifAvi(currentPath) == 1) *(aviAmount) = *(aviAmount) + 1;
  132.     }
  133.     chdir("..");
  134.     closedir(dp);
  135. }
  136. void getAviPathes(const char * dir, char ** aviPathes){
  137.     DIR *dp;
  138.     if((dp = opendir(dir)) == NULL) {
  139.         printf("cannot open directory\n");
  140.         return;
  141.     }
  142.  
  143.     char currentPath[PATH_MAX+1];
  144.  
  145.     struct dirent *entry;
  146.     struct stat statbuf;
  147.  
  148.     chdir(dir);
  149.     while((entry = readdir(dp)) != NULL) {
  150.  
  151.         strcpy(currentPath, dir);
  152.         strcat(currentPath, "/");
  153.         strcat(currentPath, entry->d_name);
  154.  
  155.         stat(entry->d_name,&statbuf);
  156.         if(S_ISDIR(statbuf.st_mode)) {
  157.             if(strcmp(".",entry->d_name) == 0 || strcmp("..",entry->d_name) == 0 || strcmp("avis",entry->d_name) == 0)
  158.                 continue;
  159.             getAviPathes(currentPath, aviPathes);
  160.         }
  161.        
  162.         if(ifAvi(currentPath) == 1){
  163.    
  164.             printf("%s\n", currentPath);
  165.             strcpy(*aviPathes,currentPath);
  166.             aviPathes++;   
  167.         }
  168.     }
  169.     chdir("..");
  170.     closedir(dp);
  171. }
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