Advertisement
filip710

drugiv2

Apr 11th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3.  
  4. #include<stdio.h>
  5. #include<windows.h>
  6.  
  7. int main(int argc, char** argv);
  8. void dirListFiles(const char* startDir);
  9.  
  10. const bigFileSize = 1024*1024*1024-1;
  11. int numOfBigFiles = 0;
  12.  
  13. FILETIME dateCreated;
  14.  
  15.  
  16.  
  17. int main(int argc, char** argv)
  18. {
  19.     const char* startDir = "C:\\";
  20.  
  21.     dirListFiles(startDir);
  22.  
  23.     printf("Big files: %d", numOfBigFiles);
  24.     SYSTEMTIME st;
  25.     char szLocalDate[255];
  26.  
  27.     FileTimeToLocalFileTime(&dateCreated, &dateCreated);
  28.     FileTimeToSystemTime(&dateCreated, &st);
  29.     GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szLocalDate, 255);
  30.  
  31.     printf("Najstarija dat %s\n", szLocalDate);
  32.     system("pause");
  33.     return 0;
  34. }
  35.  
  36. void dirListFiles(const char* startDir)
  37. {
  38.     HANDLE hFind;
  39.     WIN32_FIND_DATA wfd;
  40.     char path[MAX_PATH];
  41.  
  42.     sprintf(path, "%s\\*", startDir);
  43.     fprintf(stdout, "In Directory \"%s\"\n\n", startDir);
  44.  
  45.     if ((hFind = FindFirstFile(path, &wfd)) == INVALID_HANDLE_VALUE)
  46.     {
  47.         fprintf(stderr, "FindFirstFile failed on path = \"%s\"\n", path);
  48.     }
  49.  
  50.     BOOL cont = TRUE;
  51.     while (cont == TRUE)
  52.     {
  53.         if ((strncmp(".", wfd.cFileName, 1) != 0) && (strncmp("..", wfd.cFileName, 2) != 0) && (strncmp("$", wfd.cFileName, 1) != 0) && (strncmp("System", wfd.cFileName, 6) != 0) && (strncmp("Documents", wfd.cFileName, 9) != 0) && (strncmp("MSOCache", wfd.cFileName, 8) != 0))
  54.         {
  55.             if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  56.             {
  57.                 sprintf(path, "%s\\%s", startDir, wfd.cFileName);
  58.                 dirListFiles(path);
  59.             }
  60.             else
  61.             {
  62.                 if (wfd.nFileSizeHigh != 0 || wfd.nFileSizeLow>bigFileSize)
  63.                 {
  64.                     numOfBigFiles++;
  65.  
  66.                 }
  67.  
  68.                 if (dateCreated.dwHighDateTime == 0 && dateCreated.dwLowDateTime == 0)
  69.                 {
  70.                     dateCreated = wfd.ftCreationTime;
  71.                 }
  72.                 else if (wfd.ftCreationTime.dwHighDateTime < dateCreated.dwHighDateTime || (wfd.ftCreationTime.dwHighDateTime == dateCreated.dwHighDateTime && wfd.ftCreationTime.dwLowDateTime < dateCreated.dwLowDateTime))
  73.                     dateCreated = wfd.ftCreationTime;
  74.             }
  75.         }
  76.         cont = FindNextFile(hFind, &wfd);
  77.     }
  78.     if (GetLastError() != ERROR_NO_MORE_FILES)
  79.     {
  80.         fprintf(stderr, "FindNextFile died for some reason; path = \"%s\"\n", path);
  81.         abort();
  82.     }
  83.     if (FindClose(hFind) == FALSE)
  84.     {
  85.         fprintf(stderr, "FindClose failed\n");
  86.         abort();
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement